我是靠谱客的博主 能干摩托,这篇文章主要介绍unity接入华为sdk之原生接入,现在分享给大家,希望可以做个参考。

接入方式:as里面接入华为sdk 导出jar包给Unity使用

接入过程:仔细阅读华为文档 按照文档接入 此处省去

遇到问题1:凡是调用华为sdk的地方 提示java.lang.NoClassDefFoundError

原因:导出jar包 并不会把你通过as gradle里下载华为相关包一起导出 导致找不到相关的包

解决办法:在unity的Plugins/Android下面 建一个mainTemplate.gradle文件 重新添加相关依赖 形如下面的代码 这样就能解决包找不到的问题

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

buildscript {
    repositories {
        google()
        jcenter()
        maven {url 'https://developer.huawei.com/repo/'}
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {url 'https://developer.huawei.com/repo/'}
        flatDir {
            dirs 'libs'
        }
    }
}

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.huawei.hms:base:5.0.3.300'
    implementation 'com.huawei.hms:hwid:5.0.3.301'
    implementation 'com.huawei.hms:iap:5.0.2.300'
    implementation 'com.huawei.hms:game:5.0.3.301'
    implementation 'com.huawei.agconnect:agconnect-auth:1.4.1.300'
    implementation 'com.huawei.hms:hianalytics:5.0.4.300'
}

android {
    // compileSdkVersion 29
    // buildToolsVersion '29.0.3'

    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 29
        applicationId 'xxx.xxx.xxx'
        ndk {
            abiFilters 'armeabi-v7a'
        }
        versionCode 1
        versionName '0.1'
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb']
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }

    signingConfigs {
       release {
           storeFile file("../../xxx.keystore")
           storePassword "xxxx"
           keyAlias "xxx"
           keyPassword "xxx"
       }
   }

    buildTypes {
        debug {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
            signingConfig signingConfigs.release
            jniDebuggable true
        }
        release {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
            signingConfig signingConfigs.release
        }
    }

    packagingOptions {
        doNotStrip '*/armeabi-v7a/*.so'
    }


    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = false
        }
        abi {
            enableSplit = true
        }
    }
}

遇到问题2:华为后台下载的agconnect-services文件 不会被一起导出 Unity无法识别里面的参数配置 

 解决办法1:修改manifrst文件 手动配置appid等参数 

    <meta-data android:name="com.huawei.hms.client.appid" android:value="appid=1233(你的appid)" />

具体可以参考:https://blog.csdn.net/linxinfa/article/details/88953267

https://blog.csdn.net/qq_33515628/article/details/103508052

上面这种方法有缺陷 如果你要使用华为分析相关 这种方法就行不通 华为分析相关参数 无法配置 

 针对上面的问题 有了下面的新办法 我更推荐下面的方法

a 将agconnect-services放在unity的Plugins/Android下面 

b 从Unity官方的华为demo里面 找到这个编辑器脚本AfterBuildToDO 拷贝到自己的工程里面 demo地址:https://github.com/Unity-Technologies/HMSSDKSample

通过上面两步 就能解决agconnect-service里面参数读取不到问题 也不需要再通过manifest来配置

此外 unity现在有针对华为HMS Core的集成说明的,下篇文章会描述相关的内容 

最后

以上就是能干摩托最近收集整理的关于unity接入华为sdk之原生接入的全部内容,更多相关unity接入华为sdk之原生接入内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部