分类: Android平台
2013-07-10 17:43:48
-keep class mm.vending.**
今天在打包混淆的时候,因为使用了android-support-v4而发生混淆错误,无法打包,网上google了一下,没发现可用的,就东拼西凑的把网上各个版本拼凑了下,拼凑出下面自己可用通过的代码。
在proguard.cfg中加入以下代码:
-libraryjars libs/android-support-v4.jar //这里根据你的jar包的路径做改动
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment
不混淆webview中对javascript接口
-keep public class com.igrs.dlna.activity.webviewActivity.JavaScriptInterface
-keepclassmembers class com.igrs.dlna.activity.webviewActivity.JavaScriptInterface{
void showSource(java.lang.String,java.lang.String);
}
-keepclassmembers class com.igrs.dlna.activity.webviewActivity$InJavaScriptLocalObj {
public void showSource(java.lang.String,java.lang.String);
public void showTitle(java.lang.String);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
混淆android的jar包配置文件proguard.cfg如下
-injars libs\your_library.jar
-outjars libs\your_library_out.jar
-libraryjars 'E:\program_tools\android-sdk\platforms\android-9\android.jar'
-optimizationpasses 5
-dontusemixedcaseclassnames
-ignorewarning
-dontskipnonpubliclibraryclasses
-dontoptimize
-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
-keepclasseswithmembernames class * {
native
}
-keepclasseswithmembers class * {
public
}
-keepclasseswithmembers class * {
public
}
-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 *;
}
如上的红色文字非常重要
-injars 表示你要混淆的jar文件
-outjars 是混淆后的jar文件名
-libraryjars 是混淆时需要引用的android库
-ignorewarning 表示混淆时忽略所以的警告
-dontoptimize 不进行优化,这句代码非常重要。并且配置中不能有-dontpreverify字段;-dontpreverify在混淆jar时没有问题但是在apk应用中使用该jar后对apk进行混淆时就会失败。
如果项目中使用了jar库,则proguard.cfg文件的配置如下
-optimizationpasses 2
-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
-keepclasseswithmembernames class * {
native
}
-keepclasseswithmembers class * {
public
}
-keepclasseswithmembers class * {
public
}
-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 *;
}
上面的配置中 -optimizationpasses 只能为1,2;3以上混淆就会出错!