华为HMS core SDK,返回错误码6003解决方案
source link: https://www.daozhao.com/9878.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
最近想业余搞搞Android,所以就一边看android,一边看kotlin,第一个想了解和接入的SDK就是华为的HMS(对,支持国产)。 第一步想到的就是接入华为账号体系。
根据官网的提示对项目新建了如下工程Hello。 增加了HMS相关的东西:
在Hello/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.3.41' repositories { google() jcenter() maven {url 'https://developer.huawei.com/repo/'} // HMS Core SDK } dependencies { classpath 'com.android.tools.build:gradle:3.5.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath 'com.huawei.agconnect:agcp:1.3.1.300' // HMS Core SDK } } allprojects { repositories { google() jcenter() maven {url 'https://developer.huawei.com/repo/'} // HMS Core SDK } } task clean(type: Delete) { delete rootProject.buildDir }
在Hello/app/build.gradle
apply plugin: 'com.huawei.agconnect' // HMS Core SDK android { ... } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.core:core-ktx:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' implementation 'com.huawei.hms:hwid:5.0.1.301' // HMS Core SDK }
经过搜索才知道其实华为开发者官网的指南里面(竟然是应用内支付服务FAQ里面)有讲到这个错误码的原因
Q:连接HMS Core(APK)出现6003错误,如何处理? A:出现6003错误是由于指纹证书配置不一致导致的,请从以下方面检查:
- 确认证书指纹已经配置,并且本地客户端打包签名的证书和AppGallery Connect上配置的证书指纹是同一套证书。
- 检查证书中指纹条目,建议使用单条目。
- 如果配置完指纹,运行本地客户端仍然出现6003的错误,这是由于默认运行的是debug证书,请尝试清除HMS Core(APK)的缓存后再次运行。
搜索引擎寻他千百度,答案就在官网。
这三个可能的原因其实我排查了,但是没有搞定。应该是我不会安卓开发的缘故,我对签名证书的理解有问题,我确实是将官网的 agconnect-services.json 配置并下载了,但是我一直好奇自己本地怎么配置呢,这个json文件总不至于直接放在本地就不用管了吧,总需要在哪指定下配置文件的路径什么的吧。一直页没有细究,所以自己的6003报错其实是一直卡在这里了。。。
偶然搜到一个这样的相关答复。
原文地址 Trying to connect Huawei IAP SDK for Inapp payments - 6003 error
看来这个确实需要在本地配,不配的话怎么知道用agconnect-services.json,对吧。
上述答案给的配置其实就是在Helllo/app/build.gradle里面。 完整的配置如下:
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'com.huawei.agconnect' // HMS Core SDK android { signingConfigs { debug { storeFile file('/Users/shadow/Dev/Android/Hello/hello.keystore') keyPassword 'wodemima' keyAlias = 'key0' storePassword 'wodemima' } } compileSdkVersion 28 defaultConfig { applicationId "com.daozhao.hello" minSdkVersion 26 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" resConfigs "en", "zh-rCN" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.core:core-ktx:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' implementation 'com.huawei.hms:hwid:5.0.1.301' // HMS Core SDK }
用可视化界面的话要这么配置
File -> Project Structure -> Module -> Signing Configs
总算是不报这个错误了。。。
目前根据demo中代码来看,不报失败了,但是返回的Authorization code为null,后面接着看。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK