Android代碼混淆


這是在工程中的proguard-project.txt中發現的

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

 
從腳本中可以看到,混淆中保留了繼承自Activity、Service、Application、BroadcastReceiver、ContentProvider等基本組件以及com.android.vending.licensing.ILicensingService,
並保留了所有的Native變量名及類名,所有類中部分以設定了固定參數格式的構造函數,枚舉等等。(詳細信息請參考<proguard_path>/examples中的例子及注釋。)
讓proguard.cfg起作用的做法很簡單,就是在eclipse自動生成的default.properties文件中加上一句“proguard.config=proguard.cfg”就可以了
完整的default.properties文件應該如下:
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-15
proguard.config=proguard.cfg


Android代碼混淆,如何過濾掉反射的R文件及第三方包?
解決方案:在Proguard.cfg方件中添加以下設定:

  • 過濾R文件的混淆:

-keep class **.R$* {   *;  }

  • 過濾第三方包的混淆:

-keep class packagename.** {*;}(其中packagename為第三方包的包名)

Android導入第三方jar包,proguard混淆腳本(屏蔽警告,不混淆第三方包)
最近1個項目中 需要導入移動MM的第三方計費包,混淆時用到了如下腳本,可屏蔽警告,不混淆第三方包指定內容。
非常有效

proguard.cfg 文件

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-ignorewarnings //這1句是屏蔽警告,腳本中把這行注釋去掉
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
//這1句是導入第三方的類庫,防止混淆時候讀取包內容出錯,腳本中把這行注釋去掉
-libraryjars libs/mmbilling.jar 

-dontwarn  //dontwarn去掉警告
-dontskipnonpubliclibraryclassmembers

-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>;
}
-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

//這4句是不混淆第三方包中的指定內容,腳本中把這行注釋去掉 -keep class com.ccit.** {*; }   
-keep class ccit.** { *; }
-keep class com.aspire.**
-keep class mm.vending.**


www.J2meGame.com整理,轉載請說明。

================更多內容推薦===================================
如何反編譯APK
http://www.eoeandroid.com/thread-90027-1-1.html

Android一體化的反編譯工具
http://www.eoeandroid.com/thread-62036-1-1.html
轉自http://www.eoeandroid.com/thread-160335-1-1.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM