目录

配置混淆脚本

您编译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.**{*;} 
    -keep interface com.huawei.hms.analytics.type.HAEventType{*;}
    -keep interface com.huawei.hms.analytics.type.HAParamType{*;}
    -keep class com.huawei.hms.analytics.HiAnalyticsInstance{*;}
    -keep class com.huawei.hms.analytics.HiAnalytics{*;}
  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.layout.hms*",      
    "R.drawable.upsdk*",    
    "R.color.upsdk*",  
    "R.dimen.upsdk*",  
    "R.style.upsdk*", 
    "R.id.scroll_layout",
    "R.id.divider",
    "R.id.name_textview",
    "R.id.version_textview",
    "R.id.appsize_textview",
    "R.id.allsize_textview",
    "R.id.content_textview",
    "R.id.third_app_dl_progress_text",
    "R.id.cancel_bg",
    "R.id.third_app_dl_progressbar",
    "R.id.upsdk*",
    "R.string.upsdk*",
    "R.layout.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*,@drawable/c_buoycircle*,@drawable/hms_game*,@layout/c_buoycircle*,@layout/hms_game*,@strings/hms_game*,@strings/c_buoycircle*"
        tools:shrinkMode="strict" />