简而言之,这些类在 proguard.cfg 模板中,因为这些类可以在 AndrodiManifest.xml 中声明。
考虑这个最小的应用程序:
CustomTextView.java:
package com.example.android;
import android.content.Context;
import android.widget.TextView;
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
setText("The class name of this class is not important");
}
}
ExampleActivity.java:
package com.example.android;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class ExampleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new CustomTextView(this));
Log.i("ExampleActivity", "The class name of this class is important");
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android"
android:versionCode="1"
android:versionName="1.0">
<application>
<activity android:name=".ExampleActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
现在,没有线
-keep public class * extends android.app.Activity
在 proguard.cfg 文件中,proguard 可能会尝试将 ExampleActivity 重命名为 A。 虽然它对 AndroidManifest.xml 一无所知,所以它不会触及清单。由于 Android 操作系统使用应用程序清单中声明的类名来启动应用程序,因此 Android 操作系统将尝试实例化 ExampleActivity,但该类将不存在,因为 proguard 重命名了它!
对于CustomTextView,proguard 可以将其重命名为B,因为类的名称并不重要,因为它没有在清单中声明,仅由 proguard 将更新的代码引用当它改变CustomTextView的类名时。
以某种方式,从模板 proguard.cfg 文件引用的所有类都可以在清单中声明,因此 proguard 不得触及它们。