shwenzhang / AndResGuard

proguard resource for Android by wechat team
Apache License 2.0
8.54k stars 1.54k forks source link

华为推送hms_download_progress.xml资源混淆后,内容丢失 #370

Open Eklir opened 5 years ago

Eklir commented 5 years ago

问题描述

最近bugly上报了以java.lang.ClassNotFoundException(Didn't find class "android.view.x" ). 复现了下,集成华为推送提示用户升级安装“华为移动服务”最新版本的弹窗,点击安装按钮后,就报这个错误。 跟踪了下,是华为推送里边调用了hms_download_progress这个布局文件导致的

public AlertDialog a() {
    Builder var1 = new Builder(this.f(), this.g());
    View var2 = View.inflate(this.f(), h.a("hms_download_progress"), (ViewGroup)null);
    var1.setView(var2);
    var1.setCancelable(false);
    var1.setOnKeyListener(this.d);
    this.a = (ProgressBar)var2.findViewById(h.b("download_info_progress"));
    this.b = (TextView)var2.findViewById(h.b("hms_progress_text"));
    this.b(this.c);
    return var1.create();
  }

下边的是原始的hms_download_progress.xml的布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingEnd="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingStart="16dp"
    android:orientation="vertical" >
        <TextView
            android:id="@+id/hms_message_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="16dp"
            android:text="@string/hms_downloading_loading"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/hms_progress_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_marginTop="16dp"
            android:alpha="0.5"
            android:textSize="13sp"/>

        <RelativeLayout
            android:id="@+id/hms_progress_bar"
            android:layout_width="match_parent"
            android:layout_height="18dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="16dp"
            android:layout_below="@+id/hms_message_text">

            <ProgressBar
                android:id="@+id/download_info_progress"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="7dp"
                android:layout_centerVertical="true" />

        </RelativeLayout>

</RelativeLayout>

这个是AndResGuard混淆后,apktool反编译后找到的hms_download_progress布局文件:

<?xml version="1.0" encoding="utf-8"?>
<x />

为什么layout里边的内容找不到了,变成了???

androidResGuard版本信息

混淆白名单配置:

//huaweipush "R.dimen.upsdk*", "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.thirdapp", "R.string.upsdk_", "R.style.upsdkDlDialog", "R.style.AppTheme", "R.style.AppBaseTheme", "R.dimen.upsdkdialog", "R.color.upsdk*", "R.layout.upsdk", "R.drawable.upsdk_", "R.drawable.hms*", "R.layout.hms", "R.id.hms_",

插件版本:

 classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.17'
dreamevil commented 5 years ago

丢失的xml文件被shrinkResources 命令在打包的时候标记为unused resources了吧,可以参考下这个文章https://www.jianshu.com/p/77cbe147aea8

Eklir commented 5 years ago

@dreamevil 多谢,我试下看看。