Proguard在gradle插件3.2.1中真的区分大小写吗?

时间:2019-01-22 13:21:50

标签: proguard android-proguard

大家好,我正在为团队尝试升级gradle插件3.2.1,遇到一个奇怪的问题,如下所示的“ ClassNotFoundException”:

-22 21:09:20.881 10523-10523/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.testproguard, PID: 10523
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/testproguard/b$a;
    at com.example.testproguard.MainActivity.onCreate(MainActivity.java:15)
    at android.app.Activity.performCreate(Activity.java:6100)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614)
    at android.app.ActivityThread.access$800(ActivityThread.java:178)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5643)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.testproguard.b$a" on path: DexPathList[[zip file "/data/app/com.example.testproguard-2/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    at com.example.testproguard.MainActivity.onCreate(MainActivity.java:15) 
    at android.app.Activity.performCreate(Activity.java:6100) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614) 
    at android.app.ActivityThread.access$800(ActivityThread.java:178) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) 
    at android.os.Handler.dispatchMessage(Handler.java:111) 
    at android.os.Looper.loop(Looper.java:194) 
    at android.app.ActivityThread.main(ActivityThread.java:5643) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
    Suppressed: java.lang.ClassNotFoundException: com.example.testproguard.b$a
    at java.lang.Class.classForName(Native Method)
    at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 15 more
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

我努力寻找根案例,幸运的是,我发现有人定义了两个内部静态类,名称分别为'WWS'和'Wws'。在这两个愚蠢的类中,“ Wws”被外部类使用,但是从未使用过“ WWS”,如下:

public final class ServerUtils {

public ServerUtils() {
}

public static class ABC {
    public static final String PATH = "xxxx/xxx/";

    public static String getHost() {
        return HostGenerator.getHost("" + PATH);
    }
}

public static class WWS {
    public static final String PATH = "xxxx/xxxx/";

    public static String getHost() {
        return HostGenerator.getHost("" + PATH);
    }
}



public static class Wws {
    public static final String PATH = "xxxx/xxxx/";

    public static String getHost() {
        Log.d(PATH, PATH);
        PackageInfo packageInfo = new PackageInfo();
        packageInfo.packageName = "ttttt";
        return HostGenerator.getHost("" + PATH) + packageInfo.packageName + ServerUtils.class.getCanonicalName() + ServerUtils.Wws.class.getCanonicalName();
    }
} }

这是我的整个proguard文件

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-keepattributes *Annotation*,InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-dontoptimize
-ignorewarnings

此代码在调试模式和gradle插件2.3.3中可以正常工作,但是在我尝试使用proguard进行发行版本时不起作用。

我尝试设置“ android.enableR8 = false” ,但无效

我怀疑在保护收缩代码时,它发现未使用“ WWS”,因此删除了“ WWS”,并错误地删除了“ Wws” Proguard在gradle插件3.2.1中真的区分大小写吗?还是在新的gradle插件中存在错误?

0 个答案:

没有答案