目录

配置混淆脚本

您编译APK前需要配置混淆配置文件,避免混淆HMS Core SDK导致功能异常。

  1. 打开应用级根目录下的混淆配置文件“proguard-rules.pro”,需要加入排除HMS Core SDK的混淆配置。

    -ignorewarnings 
    -keepattributes *Annotation* 
    -keepattributes Exceptions 
    -keepattributes InnerClasses 
    -keepattributes Signature 
    -keepattributes SourceFile,LineNumberTable 
    -keep class com.huawei.hianalytics.**{*;} 
    -keep class com.huawei.updatesdk.**{*;} 
    -keep class com.huawei.hms.**{*;}

  2. 如果您使用了AndResGuard,需要在应用级的“build.gradle”文件中加入AndResGuard允许清单。

    "R.string.agc*",
    "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*"

  3. (可选)当您启用R8资源缩减(项目级“build.gradle”文件中“shrinkResources”属性为“true”)和严格引用检查(“res/raw/keep.xml”文件中的“shrinkMode”为“strict”)时,请您配置“keep.xml”文件手动保留layout资源,确保应用正常通过华为应用市场上架审核。

    <?xml version="1.0" encoding="utf-8"?>
    <resources xmlns:tools="http://schemas.android.com/tools"
        tools:keep="@layout/hms_download_progress,@drawable/screen_off,@layout/upsdk*"
        tools:shrinkMode="strict" />