android关于annotation的混淆错误

newfarhui 2012-07-30

在之前的sdk版本中,不会有这个问题,从level8开始引入了注释。如果代码中有用到,而没有处理,就会出现错误的。主要是注释引起的。

proguard.cfg还是这个配置文件。

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

-libraryjars D:\\libs\\commons-codec-1.4.jar
-libraryjars E:\\android-sdk-windows\\platforms\\android-15\\android.jar
-libraryjars E:\\android-sdk-windows\\tools\\support\\annotations.jar
//这一句加不加似乎都不影响的。

-libraryjars ./libs/apache-mime4j-core-0.7.jar
-libraryjars ./libs/httpmime-4.1.2.jar
-libraryjars ./libs/signpost-commonshttp4-1.2.1.2.jar
-libraryjars ./libs/signpost-core-1.2.1.2.jar

-keep public class org.apache.james.mime4j.** { public protected *; }
-keep public class org.apache.james.mime4j.codec.** { public protected *; }
-keep public class org.apache.james.mime4j.io.** { public protected *; }
-keep public class org.apache.james.mime4j.parser.** { public protected *; }
-keep public class org.apache.james.mime4j.stream.** { public protected *; }
-keep public class org.apache.james.mime4j.util.** { public protected *; }

-keep public class org.apache.http.entity.mime.** { public protected *; }
-keep public class org.apache.http.entity.mime.content.** { public protected *; }

-keep public class oauth.signpost.commonshttp.** { public protected *; }
-keep public class oauth.signpost.** { public protected *; }
-keep public class oauth.signpost.basic.** { public protected *; }
-keep public class oauth.signpost.exception.** { public protected *; }
-keep public class oauth.signpost.http.** { public protected *; }
-keep public class oauth.signpost.signature.** { public protected *; }

-keep public class com.google.gdata.util.common.base.** { public protected *; }

-keep public class oauth.signpost.commonshttp.** { public protected *; }

这是前面的部分,就要是一些引入的jar不混淆,目前我也没有发现好办法,只有一个包一个包的写了。

然后是:
-keep public class android.** { public protected private *; }


-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

-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 *;
}

最后加上一句:
-keepattributes *Annotation*就可以处理注释属性了。

相关推荐