2013-10-03 158 views
8

我在我的應用程序上運行了proguard工具來混淆。我知道當發生混淆時,proguard會縮小並優化應用程序,因爲它認爲合適。所以混淆後,應用程序打開正確,然後當我嘗試登錄它崩潰。我能得到的最好的結果就是這個日誌,因爲我連接了設備。Android應用程序在proguard混淆後崩潰

10-03 11:12:47.384: E/AndroidRuntime(15058): FATAL EXCEPTION: AsyncTask #1 
10-03 11:12:47.384: E/AndroidRuntime(15058): java.lang.RuntimeException: An error  occured while executing doInBackground() 
10-03 11:12:47.384: E/AndroidRuntime(15058): at  android.os.AsyncTask$3.done(AsyncTask.java:299) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at  java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at java.util.concurrent.FutureTask.run(FutureTask.java:239) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at java.lang.Thread.run(Thread.java:856) 
10-03 11:12:47.384: E/AndroidRuntime(15058): Caused by: java.lang.ExceptionInInitializerError 
10-03 11:12:47.384: E/AndroidRuntime(15058): at com.winwin.a.d.c.doInBackground(Unknown Source) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at com.winwin.a.d.c.doInBackground(Unknown Source) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at android.os.AsyncTask$2.call(AsyncTask.java:287) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
10-03 11:12:47.384: E/AndroidRuntime(15058): ... 4 more 
10-03 11:12:47.384: E/AndroidRuntime(15058): Caused by: java.lang.ExceptionInInitializerError 
10-03 11:12:47.384: E/AndroidRuntime(15058): at com.winwin.a.c.d.<clinit>(Unknown Source) 
10-03 11:12:47.384: E/AndroidRuntime(15058): ... 8 more 
10-03 11:12:47.384: E/AndroidRuntime(15058): Caused by: java.lang.ExceptionInInitializerError 
10-03 11:12:47.384: E/AndroidRuntime(15058): at com.b.a.c.ad.<clinit>(Unknown Source) 
10-03 11:12:47.384: E/AndroidRuntime(15058): ... 9 more 
10-03 11:12:47.384: E/AndroidRuntime(15058): Caused by: java.lang.NoSuchFieldError: ANY 
10-03 11:12:47.384: E/AndroidRuntime(15058): at java.lang.Class.getDeclaredAnnotation(Native Method) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at java.lang.Class.getAnnotation(Class.java:260) 
10-03 11:12:47.384: E/AndroidRuntime(15058): at com.b.a.c.f.ag.<clinit>(Unknown Source) 

我以爲這會是因爲proguard已經刪除了一些它認爲不必要的類或方法,因此導致崩潰。我所做的是我又跑proguard的這段時間,包括

-dontobfuscate 

,所以我想的工具來收縮和優化,但不混淆,所以我可以再得到一個適當的閱讀來少了什麼。但是,當我使用這個工具生成apk時,它完美地運行了。問題不是混淆。

所以我不知道現在該做什麼。

有沒有人有任何想法?

* 編輯 *

這裏是我的配置文件

To enable ProGuard in your project, edit project.properties 
to define the proguard.config property as described in that file. 

Add project specific ProGuard rules here. 
By default, the flags in this file are appended to flags specified 
in ${sdk.dir}/tools/proguard/proguard-android.txt 
You can edit the include path and order by changing the ProGuard 
include property in project.properties. 

For more details, see 
http://developer.android.com/guide/developing/tools/proguard.html 

Add any project specific keep options here: 

-libraryjars libs/crashlytics.jar 

-keep class com.facebook.** { 
*; 
} 


-keepattributes Signature 

-optimizationpasses 5 
-dontusemixedcaseclassnames 
-dontskipnonpubliclibraryclasses 
-dontpreverify 
-verbose 

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 

-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.app.backup.BackupAgentHelper 
-keep public class * extends android.preference.Preference 
-keep public class com.android.vending.licensing.ILicensingService 

keep all classes that might be used in XML layouts 
-keep public class * extends android.view.View 
-keep public class * extends android.app.Fragment 
-keep public class * extends android.support.v4.Fragment 

-keepattributes *Annotation*, EnclosingMethod 

-keep class com.winwin.** { *; } 
-keepnames class org.codehaus.jackson.** { *; } 


-dontoptimize 
-dontshrink 

keep all public and protected methods that could be used by java reflection 
-keepclassmembernames class * { 
public protected <methods>; 
} 

-keepclasseswithmembernames class * { 
native <methods>; 
} 

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

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


-keepclassmembers enum * { 
    public static **[] values(); 
    public static ** valueOf(java.lang.String); 
} 

-keep class * implements android.os.Parcelable { 
public static final android.os.Parcelable$Creator *; 
} 

-dontwarn **CompatHoneycomb 
-dontwarn org.htmlcleaner.* 

-dontwarn com.fasterxml.jackson.databind.ext.** 

If your project uses WebView with JS, uncomment the following 
and specify the fully qualified class name to the JavaScript interface 
class: 
-keepclassmembers class fqcn.of.javascript.interface.for.webview { 
public *; 
} 

======================= ===

這裏是我的Project Explorer面板


Android的支持-V7-程序兼容性/ ConverserSdk/ 的Facebook/ 的Google Play-services_lib/ 庫/ 主要/ MainWs/ SlidingMenu


所以我主要是依賴於每個其他包。

+0

你有你的doInBackground方法的getter setter方法? – GrIsHu

+0

@GrIsHu我在doInBackground()中沒有getter或setter方法,但是在這個方法中有錯誤檢查,如果有錯誤,我調用具有setter方法的方法..這可能是一個因素嗎? –

+0

您有一些代碼(猜測:某些JSON對象映射程序庫)依賴反射來訪問註釋,並且在使用反射訪問時破壞混淆器。你需要添加'-keepattributes * Annotation *,EnclosingMethod -keep class reflection.using.package.name。** {*; }' – laalto

回答

4

你需要保存一些類被混淆。 Android項目的典型proguard配置文件如下。這個環節應該是有用的:Proguard for Android

-optimizationpasses 5 
-dontusemixedcaseclassnames 
-dontskipnonpubliclibraryclasses 
-dontpreverify 
-verbose 
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 

-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.app.backup.BackupAgentHelper 
-keep public class * extends android.preference.Preference 
-keep public class com.android.vending.licensing.ILicensingService 
-keep public class * implements java.io.Serializable 
-keep public class * extends android.support.v4.app.Fragment 
-keep public class * extends android.support.v4.app.ListFragment 



-keep public class org.spongycastle.** { 
    <fields>; 
    <methods>; 
} 

-keep public class org.apache.** { 
    <fields>; 
    <methods>; 
} 

-ignorewarnings 

-keepclasseswithmembernames class * { 
    native <methods>; 
} 

-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.app.Activity { 
    public void *(android.view.View); 
} 


-keepclassmembers enum * { 
    public static **[] values(); 
    public static ** valueOf(java.lang.String); 
} 

-keep class * implements android.os.Parcelable { 
    public static final android.os.Parcelable$Creator *; 
} 

-keepclassmembers class * implements java.io.Serializable { 
    static final long serialVersionUID; 
    private static final java.io.ObjectStreamField[] serialPersistentFields; 
    private void writeObject(java.io.ObjectOutputStream); 
    private void readObject(java.io.ObjectInputStream); 
    java.lang.Object writeReplace(); 
    java.lang.Object readResolve(); 
} 
+0

感謝您的回覆,我已經去過那裏了,並且關注了這個網站。 –

0

快速有效的解決方案

-keep class com.fasterxml.jackson.annotation.** {*;} 
-keep class com.fasterxml.jackson.core.** {*;} 
-keep class com.fasterxml.jackson.databind.** {*;} 
相關問題