目录

Configuring Obfuscation Scripts

Before building the APK, configure the obfuscation configuration file to prevent the HMS Core SDK from being obfuscated.

  1. Open the obfuscation configuration file proguard-rules.pro in the app directory of your project and add configurations to exclude the HMS Core SDK from obfuscation.
    -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. If you are using AndResGuard, add its trustlist to the build.gradle file in the app directory of your project.
    "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. (Optional) Configure the keep.xml file as follows to keep layout resources if you have enabled R8 resource shrinking (with shrinkResources being set to true in the project-level build.gradle file) and strict reference checks (with shrinkMode being set to strict in the res/raw/keep.xml file). Not keeping layout resources will lead to app rejection during release to HUAWEI AppGallery.
    <?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" />