Before building the APK, configure obfuscation scripts to prevent the HMS SDK from being obfuscated. If obfuscation arises, the HMS SDK may not function properly.
The configuration file in Android Studio is proguard-rules.pro, and that in Eclipse is proguard-project.txt.
Step 1 Open the obfuscation script file of your project.
Step 2 Add configurations to exclude the HMS SDK from obfuscation.
- -ignorewarnings
- -keepattributes *Annotation*
- -keepattributes Exceptions
- -keepattributes InnerClasses
- -keepattributes Signature
- -keepattributes SourceFile,LineNumberTable
- -keep class com.hianalytics.android.**{*;}
- -keep class com.huawei.updatesdk.**{*;}
- -keep class com.huawei.hms.**{*;}
Step 3 If you have used AndResGuard, add it to the whitelist in the obfuscation script file.
- "R.string.hms*",
- "R.string.connect_server_fail_prompt_toast",
- "R.string.getting_message_fail_prompt_toast",
- "R.string.no_available_network_prompt_toast",
- "R.string.third_app_*",
- "R.string.upsdk_*",
- "R.layout.hms*",
- "R.layout.upsdk_*",
- "R.drawable.upsdk*",
- "R.color.upsdk*",
- "R.dimen.upsdk*",
- "R.style.upsdk*",
- "R.string.agc*"