2016-03-02 86 views
0

我的應用程序工作正常,沒有應用保護規則,但出於安全目的,我必須在我的應用程序中應用保護規則。 我在應用規則並嘗試運行我的應用程序時遇到了這些錯誤。Android應用程序崩潰與proguard規則

FATAL EXCEPTION: main 
                    Process: com.nearely.nearelysales, PID: 4275 
                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nearely.nearelysales/com.nearely.nearelysales.activities.MainActivity}: java.lang.NullPointerException 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                     at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                     at android.os.Looper.loop(Looper.java:136) 
                     at android.app.ActivityThread.main(ActivityThread.java:5001) 
                     at java.lang.reflect.Method.invokeNative(Native Method) 
                     at java.lang.reflect.Method.invoke(Method.java:515) 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                     at dalvik.system.NativeStart.main(Native Method) 
                    Caused by: java.lang.NullPointerException 
                     at com.nearely.nearelysales.activities.MainActivity.k(Unknown Source) 
                     at com.nearely.nearelysales.activities.MainActivity.onCreate(Unknown Source) 
                     at android.app.Activity.performCreate(Activity.java:5231) 
                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)  
                     at android.app.ActivityThread.access$800(ActivityThread.java:135)  
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)  
                     at android.os.Handler.dispatchMessage(Handler.java:102)  
                     at android.os.Looper.loop(Looper.java:136)  
                     at android.app.ActivityThread.main(ActivityThread.java:5001)  
                     at java.lang.reflect.Method.invokeNative(Native Method)  
                     at java.lang.reflect.Method.invoke(Method.java:515)  
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)  
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)  
                     at dalvik.system.NativeStart.main(Native Method)   

這裏是我的progurd規則文件:

proguard-rules.pro

-injars  libs 
-outjars  bin/classes-processed.jar 
# -libraryjars C:\dev\android-sdk\platforms\android-23\android.jar 

-dontpreverify 
-repackageclasses '' 
-allowaccessmodification 
-optimizations !code/simplification/arithmetic 
-keepattributes *Annotation* 

-keep public class * extends android.app.Activity 
-keep public class * extends android.app.Application 
-keep public class * extends android.app.Service 
-keep public class * extends android.content.BroadcastReceiver 
-keep public class * extends android.content.ContentProvider 

-keep public class * extends android.view.View { 
    public <init>(android.content.Context); 
    public <init>(android.content.Context, android.util.AttributeSet); 
    public <init>(android.content.Context, android.util.AttributeSet, int); 
    public void set*(...); 
} 

-keepclasseswithmembers class * { 
    public <init>(android.content.Context, android.util.AttributeSet); 
} 

-keepclasseswithmembers class * { 
    public <init>(android.content.Context, android.util.AttributeSet, int); 
} 

-keepclassmembers class * extends android.content.Context { 
    public void *(android.view.View); 
    public void *(android.view.MenuItem); 
} 

-keepclassmembers class * implements android.os.Parcelable { 
    static ** CREATOR; 
} 

-keepclassmembers class **.R$* { 
    public static <fields>; 
} 

-keepclassmembers class * { 
    @android.webkit.JavascriptInterface <methods>; 
} 

-dontwarn butterknife.internal.** 
-keep class **$$ViewInjector { *; } 
-keepnames class * { @butterknife.InjectView *;} 

-keep class javax.ws.rs.** { *; } 
-dontwarn org.immutables.gson.** 

-dontwarn android.test.** 
-dontwarn org.junit.** 
+0

從您的日誌中可以清楚地看到崩潰發生在'MainActivity'中。確保你已經爲你正在使用的所有圖書館添加了專業排除。檢查您是否排除了在MainActivity中使用的庫 –

+0

@MuchOverflow我只在MainActivity中使用了Volley庫。我應該排除哪些內容?你能給我個建議嗎? – DhavalThakor

+2

檢查這個帖子http://stackoverflow.com/questions/21816643/volley-seems-not-working-after-proguard-obfuscate – AndroidRuntimeException

回答

4

好像你已經使用截擊和使用ProGuard崩潰您的應用程序。 您可以將此行寫入您的proGuard

-keep class org.apache.commons.logging.**