混淆流程
- #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
前面的 #号去掉,在生成包的时候就会去查看 proguard-project.txt 中的规则,然后进行混淆
- 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
- *
- 以上来自:【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
如果你们混淆的时候遇到了什么问题,或者已经解决,烦请各位将解决办法留下,谢谢