启用 Proguard 抛出异常

Enabling Proguard Throws Exception

我在我的项目中添加了一些外部库并且它工作正常,但是当我启用混淆器时它每次都会抛出异常。我试图从混淆器中排除库,但我的代码不起作用。

gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.android.support:support-v4:21.0.3'
}

proguard-rules.pro

-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
-keep enum android.support.v7.** { *; }

-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep enum android.support.v4.** { *; }

-keep class com.google.** { *; }
-keep interface com.google.** { *; }
-keep enum com.google.** { *; }

错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{in.zeitech.appprotector/in.zeitech.appprotector.activities.LockAppActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
            at android.app.ActivityThread.access0(ActivityThread.java:128)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4517)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at in.zeitech.appprotector.activities.LockAppActivity.onCreate(Unknown Source)
            at android.app.Activity.performCreate(Activity.java:4470)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
            at android.app.ActivityThread.access0(ActivityThread.java:128)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4517)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
            at dalvik.system.NativeStart.main(Native Method)

我正在使用 gson 库并在 proguard 及其作品中尝试了这一行。

-keepattributes Signature