App 混淆 – 热爱改变生活
我的GitHub GitHub |     登录
  • If you can't fly, then run; if you can't run, then walk; if you can't walk, then crawl
  • but whatever you do, you have to keep moving forward。
  • “你骗得了我有什么用,这是你自己的人生”
  • 曾有伤心之地,入梦如听 此歌

App 混淆

Android其他 sinvader 5711℃ 0评论

混淆流程

  • 1. 在 project.properties 中将
    1. #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

    前面的 #号去掉,在生成包的时候就会去查看 proguard-project.txt 中的规则,然后进行混淆

  • 2. 对 proguard-project.txt 中的规则进行编写,详见【一个 android 的开发者】以及【Android 混淆代码总结】,在对 libs 下面的 jar 包写混淆代码的时候,可使用下面的代码自动生成,防止出错
    1. public class MainClass {
    2. public static void main(String[] args) {
    3. String path = "D:\\workspace\\ExampleApplication";
    4. path = path + "/libs";
    5. File file = new File(path);
    6. if (file.exists()) {
    7. getField(file);
    8. }
    9. }
    10. private static void getField(File file){
    11. if (file.isDirectory()) {
    12. listFields(file);
    13. }else if(file.isFile()&&file.getName().endsWith("jar")){
    14. String path=file.getAbsolutePath();
    15. System.out.println("-libraryjars " + path.substring(path.indexOf("libs")).replace("\\", "/"));
    16. }
    17. }
    18.  
    19. private static void listFields(File file){
    20. File[] files = file.listFiles();
    21. for (int i = 0; i < files.length; i++) {
    22. getField(files[i]);
    23. }
    24. }
    25. }

    混淆注意事项

    应用中加入了百度地图 sdk

    在 proguard-project.txt 里面加入下面的代码:

    1. -keep class com.baidu.** {
    2. *;
    3. }

    不要写成 (具体括号错误的是什么给忘了):

    1. -keep class com.baidu.** {
    2. public *;
    3. }

    应用中加入了 shareSDK

    在文件中添加:

    1. -keep class cn.sharesdk.**{*;}
    2. -keep class com.sina.**{*;}
    3. -keep class **.R;* {*;}
    4. keepclass.R;-keep class **.R{*;}
    5. dontwarncn.sharesdk.-dontwarn cn.sharesdk.**
    6. dontwarn.R-dontwarn **.R*
    7.  
    8. 以上来自:【mob 移动开发者服务平台
    9. 我这里还加了下面的东西:
    10. -dontwarn cn.sharesdk.onekeyshare.**
    11. -keep class cn.sharesdk.onekeyshare.**
    12. -dontwarn net.sourceforge.simcpux.**
    13. -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

    如果你们混淆的时候遇到了什么问题,或者已经解决,烦请各位将解决办法留下,谢谢

  • ¥ 有帮助么?打赏一下~

    转载请注明:热爱改变生活.cn » App 混淆


    本博客只要没有注明“转”,那么均为原创。 转载请注明链接:sumile.cn » App 混淆

    喜欢 (0)
    发表我的评论
    取消评论
    表情

    如需邮件形式接收回复,请注册登录

    Hi,你需要填写昵称和邮箱~

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址