当前位置:   article > 正文

unity接入华为sdk之原生接入_unity openharmony sdk

unity openharmony sdk

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

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

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

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

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

  1. // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
  2. buildscript {
  3. repositories {
  4. google()
  5. jcenter()
  6. maven {url 'https://developer.huawei.com/repo/'}
  7. }
  8. dependencies {
  9. classpath 'com.android.tools.build:gradle:3.2.0'
  10. classpath 'com.huawei.agconnect:agcp:1.3.1.300'
  11. }
  12. }
  13. allprojects {
  14. repositories {
  15. google()
  16. jcenter()
  17. maven {url 'https://developer.huawei.com/repo/'}
  18. flatDir {
  19. dirs 'libs'
  20. }
  21. }
  22. }
  23. apply plugin: 'com.android.application'
  24. apply plugin: 'com.huawei.agconnect'
  25. dependencies {
  26. implementation fileTree(dir: 'libs', include: ['*.jar'])
  27. implementation 'com.huawei.hms:base:5.0.3.300'
  28. implementation 'com.huawei.hms:hwid:5.0.3.301'
  29. implementation 'com.huawei.hms:iap:5.0.2.300'
  30. implementation 'com.huawei.hms:game:5.0.3.301'
  31. implementation 'com.huawei.agconnect:agconnect-auth:1.4.1.300'
  32. implementation 'com.huawei.hms:hianalytics:5.0.4.300'
  33. }
  34. android {
  35. // compileSdkVersion 29
  36. // buildToolsVersion '29.0.3'
  37. compileSdkVersion **APIVERSION**
  38. buildToolsVersion '**BUILDTOOLS**'
  39. compileOptions {
  40. sourceCompatibility JavaVersion.VERSION_1_8
  41. targetCompatibility JavaVersion.VERSION_1_8
  42. }
  43. defaultConfig {
  44. minSdkVersion 19
  45. targetSdkVersion 29
  46. applicationId 'xxx.xxx.xxx'
  47. ndk {
  48. abiFilters 'armeabi-v7a'
  49. }
  50. versionCode 1
  51. versionName '0.1'
  52. }
  53. lintOptions {
  54. abortOnError false
  55. }
  56. aaptOptions {
  57. noCompress = ['.unity3d', '.ress', '.resource', '.obb']
  58. ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
  59. }
  60. signingConfigs {
  61. release {
  62. storeFile file("../../xxx.keystore")
  63. storePassword "xxxx"
  64. keyAlias "xxx"
  65. keyPassword "xxx"
  66. }
  67. }
  68. buildTypes {
  69. debug {
  70. minifyEnabled false
  71. useProguard false
  72. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
  73. signingConfig signingConfigs.release
  74. jniDebuggable true
  75. }
  76. release {
  77. minifyEnabled false
  78. useProguard false
  79. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
  80. signingConfig signingConfigs.release
  81. }
  82. }
  83. packagingOptions {
  84. doNotStrip '*/armeabi-v7a/*.so'
  85. }
  86. bundle {
  87. language {
  88. enableSplit = false
  89. }
  90. density {
  91. enableSplit = false
  92. }
  93. abi {
  94. enableSplit = true
  95. }
  96. }
  97. }

遇到问题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的集成说明的,下篇文章会描述相关的内容 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/322905
推荐阅读
相关标签
  

闽ICP备14008679号