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

Mayism
Huawei Developers
Published in
2 min readMar 9, 2021

Background:

Huawei provides agconnect-services.json for HMS Core SDK integration, which saves us a lot of hassle. We need to get the file and add it to our project directory. The file contains project information we created in AppGallery Connect, including appid and cpid.

Symptom:

The API call in the integration failed, and two errors are reported in the log, the first of which is that appid and cpid cannot be found, and the other is the result code 907135000 is reported.

The following error information is recorded in the logs:

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

TroubleShooting:

According to the log information, the agconnect-services.json file cannot be found. After checking the official documentation and consulting with Huawei technical support, I have made the following summary:

1. Copy the agconnect-services.json file to the app directory of your project, as shown in the following figure.

2. Check whether applicationId in the app-level build.gradle file shares the same package name as that configured in AppGallery Connect. The name is case sensitive.

3. Go to buildscript > dependencies in the project-level build.gradle file and check whether the AppGallery Connect plug-in configuration has been added. Sample code:

buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
...
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
}
}

4. Check whether the following configuration has been added to the app-level build.gradle file:

apply plugin: ‘com.huawei.agconnect’

Please note that this configuration must be added to the next line of apply plugin: ‘com.android.application. Otherwise, an error may occur.

5. If you are releasing a package on multiple platforms, the preceding method may not solve the problem. In this case, you can try this method:

Add the JSON file to the app directory and define appid and cpid in manifest.json by adding the following code:

<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>

Query cpid in the agconnect-services.json file.

Thanks for reading. I hope you found this post helpful!

--

--