无简介
混淆流程
-
1.在project.properties中将
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
前面的#号去掉,在生成包的时候就会去查看proguard-project.txt中的规则,然后进行混淆
-
2.对proguard-project.txt中的规则进行编写,详见【一个android的开发者】以及【Android 混淆代码总结】,在对libs下面的jar包写混淆代码的时候,可使用下面的代码自动生成,防止出错
public class MainClass {
public static void main(String[] args) {
String path = “D:\\workspace\\ExampleApplication”;
path = path + “/libs”;
File file = new File(path);
if (file.exists()) {
getField(file);
}
}
private static void getField(File file){
if (file.isDirectory()) {
listFields(file);
}else if(file.isFile()&&file.getName().endsWith(“jar”)){
String path=file.getAbsolutePath();
System.out.println(“-libraryjars " + path.substring(path.indexOf(“libs”)).replace(”\\", “/”));
}
}private static void listFields(File file){
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
getField(files[i]);
}
}
}混淆注意事项
应用中加入了百度地图sdk
在proguard-project.txt里面加入下面的代码:
-keep class com.baidu.** {
*;
}不要写成(具体括号错误的是什么给忘了):
-keep class com.baidu.** {
public *;
}应用中加入了shareSDK
在文件中添加:
-keep class cn.sharesdk.**{*;}
-keep class com.sina.**{*;}
-keep class **.R$* {*;}
-keep class **.R{*;}
-dontwarn cn.sharesdk.**
-dontwarn **.R$*以上来自:【mob移动开发者服务平台】
我这里还加了下面的东西:
-dontwarn cn.sharesdk.onekeyshare.**
-keep class cn.sharesdk.onekeyshare.**
-dontwarn net.sourceforge.simcpux.**
-keep class net.sourceforge.simcpux.**应用中使用了OKHttp
-dontwarn com.squareup.okhttp.** -keep class com.squareup.okhttp.** { *;} -dontwarn okio.**
一般情况下要混淆的
-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 [v_qing]如果你们混淆的时候遇到了什么问题,或者已经解决,烦请各位将解决办法留下,谢谢[/v_qing]