2012-06-07 66 views
4

当我通过Export > Export Android Application或通过Android Tools > Export Signed Application Package导出我的应用程序时,我无法获得Proguard的工作。使用Eclipse ADT插件导出时,Proguard不起作用R19

我所知道的有关如何启用Proguard的是取消对该行

proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt 

project.properties

我试着把我的配置文件放在那里。也不行。

导出包中的classes.dex文件包含类私有方法的名称,如onConfirmButtonClicked。所以Proguard有超过99%的机会没有完成它的工作。

之后,我在proguard-project.txt文件中放入了一些随机字符,但没有收到任何错误。构建的详细输出根本不涉及Proguard。

我在想那里有什么问题。

+0

您如何看到classes.dex文件 - 包含任何特定的方法?它似乎包含垃圾人物,即使没有proguard。 – Jasper

回答

0

Proguard的做工作,当您导出项目到一个.apk文件,你应该把你的文件(.cfg)所需要的配置,并且指向该文件在您的project.properties

proguard.config=${dir}\YOURCONFIGFILE.cfg 

并且在该配置文件中,您应该告诉proguard以保留项目中的所有关键元素。例如:

-injars  bin/classes 
-injars  libs 
-outjars  bin/classes-processed.jar 
-libraryjars /usr/local/java/android-sdk/platforms/android-9/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>; 
} 

希望这有助于!