文档管理中心

配置混淆脚本

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

  1. 在应用级根目录下打开混淆配置文件“proguard-rules.pro”,加入排除HMS Core SDK的混淆配置脚本。
    Awareness SDK 1.0.7.300及之后的版本无需加入排除HMS Core SDK的混淆配置。
    收起
    自动换行
    深色代码主题
    复制
    1. -ignorewarnings
    2. -keepattributes *Annotation*
    3. -keepattributes Exceptions
    4. -keepattributes InnerClasses
    5. -keepattributes Signature
    6. -keepattributes SourceFile,LineNumberTable
    7. -keep class com.huawei.hianalytics.**{*;}
    8. -keep class com.huawei.updatesdk.**{*;}
    9. -keep class com.huawei.hms.**{*;}
  2. 如果您使用了AndResGuard,需要在应用级的“build.gradle”文件中加入AndResGuard允许清单。
    收起
    自动换行
    深色代码主题
    复制
    1. "R.string.hms*",
    2. "R.string.connect_server_fail_prompt_toast",
    3. "R.string.getting_message_fail_prompt_toast",
    4. "R.string.no_available_network_prompt_toast",
    5. "R.string.third_app_*",
    6. "R.string.upsdk_*",
    7. "R.layout.hms*",
    8. "R.layout.upsdk_*",
    9. "R.drawable.upsdk*",
    10. "R.color.upsdk*",
    11. "R.dimen.upsdk*",
    12. "R.style.upsdk*",
    13. "R.string.agc*"
  3. (可选)当您启用R8资源缩减(项目级“build.gradle”文件中shrinkResources属性为“true”)和严格引用检查(“res/raw/keep.xml”文件中的shrinkMode“strict”)时,请您配置“keep.xml”文件手动保留layout资源,确保应用正常通过华为应用市场上架审核。
    收起
    自动换行
    深色代码主题
    复制
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <resources xmlns:tools="http://schemas.android.com/tools"
    3. tools:keep="@layout/hms_download_progress,@drawable/screen_off"
    4. tools:shrinkMode="strict" />
在 指南 中进行搜索
请输入您想要搜索的关键词