android代碼混淆筆記

來源:互聯網
上載者:User

android代碼混淆筆記

混淆處理的apk被反編譯後代碼中包名類名等都變成abcd之類,很難看懂。

使用代碼混淆,啟用混淆器,對相關檔案進行編輯,然後打包簽名就可以了;

------------

在2.3的版本中,項目中有這個檔案 proguard.cfg (沒有的可以手動添加)

添加一句: proguard.config=proguard.cfg

proguard.cfg檔案中內容:

-optimizationpasses 5-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 com.android.vending.licensing.ILicensingService-keepclasseswithmembernames class * {    native ;}-keepclasseswithmembernames class * {    public (android.content.Context, android.util.AttributeSet);}-keepclasseswithmembernames class * {    public (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.0以後的版本,項目中的檔案是project.properties和proguard-project.txt。

開啟project.properties,取消下面這行代碼的注釋:

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

預設的設定是不帶最佳化功能的,可以用以下設定加上代碼最佳化功能:
#proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

-------------------------------------------------------

proguard-project.txt 檔案的一些編輯規則:

-libraryjars libs/android-support-v4.jar

-libraryjars libs 載入第三方Jar包

-ignorewarnings 去除代碼中的警告


-keep class com.xxx.xxx.**

-keep 保留不混淆的類

此類的公用方法保留,不混淆。
-keep class com.xx.xx.Test{
public *;
}

保護指定的類檔案和類的成員

-keep class * implements android.os.Parcelable {

public static final android.os.Parcelable$Creator *;
}


----------------------------------------------------

用Eclipse工具打包簽名:

在Eclipse選中工程項目,右鍵菜單--> Android Tools

---> Export Signed Application Package...帶RSA數位簽章

---> Export Unsigned Application Package...不帶數位簽章

選擇一種方式按照嚮導操作,產生的Apk就是混淆處理過的。

----------------------------------------

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.