HMS Core SDK集成测试找不到appid和cpid怎么办?

What Can I Do if appid and cpid Cannot Be Found During an HMS Core SDK Integration Test?

我集成了HMS Core SDK,在SDK中调用了api,在日志中failed.And报了两个错误,第一个是找不到appid和cpid , 另一个是报告的结果代码 907135000。 日志中记录了以下错误信息:

E/HMSSDK_AGCUtils: In getMetaDataAppId, Failed to read meta data for the AppID.
E/HMSSDK_AGCUtils: Get client/app_id failed: java.io.FileNotFoundException: agconnect-services.json
E/HMSSDK_AGCUtils: The client/app_id is null.
E/SecurityResourcesReader: KEY is null return def directly
I/HMSSDK_AGCUtils: In getMetaDataCpId, Failed to read meta data for the CpId.
E/HMSSDK_AGCUtils: Get client/cp_id failed: java.io.FileNotFoundException: agconnect-services.json
E/HMSSDK_AGCUtils: The client/cp_id is null.
I/HMSSDK_HmsClient: receive msg status_code:1, error_code 907135000, api_name:core.getNoticeIntent, app_id:|, pkg_name:com.appservicetest.huawei, session_id:*, transaction_id:000000000Intent20201105190645844381286, resolution:null

  1. 复制agconnect-services.json文件到你项目的app目录下,如下图。

  1. 检查app级build.gradle文件中的applicationId是否同名在 AppGallery Connect 中配置的。名称区分大小写。

  2. 转到项目级别的 buildscript > dependencies build.gradle 文件,查看是否添加了AppGallery Connect插件配置

    示例代码:

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

dependencies {
...
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
}
}
  1. 查看app级build.gradle文件是否添加了如下配置:

应用插件:'com.huawei.agconnect'

请注意,此配置必须添加到应用插件的下一行:'com.android.application。否则可能会出错。

  1. 如果您在多个平台上发布一个包,上述方法可能无法解决问题。这种情况,你可以试试这个方法:

将JSON文件添加到app目录下,定义appidcpidmanifest.json 中添加以下代码:

<meta-data  
    android:name="com.huawei.hms.client.appid"  
    <!-- Replace xxx with the actual app ID, which can be obtained on the App information page. --> -->  
    android:value="appid=xxx">  
</meta-data>
<!-- Replace xxx with the actual payment ID, which can be obtained from the app's IAP information. --> -->
<meta-data
    android:name="com.huawei.hms.client.cpid"
    android:value="cpid=xxx">
</meta-data>

agconnect-services.json文件中查询cpid