編輯:關於android開發
Intellij idea 和android studio 代碼給混淆
一、指令說明
-optimizationpasses 5 # 指定代碼的壓縮級別
-dontusemixedcaseclassnames # 是否使用大小寫混合
-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 * extends android.app.backup.BackupAgentHelper # 保持哪些類不被混淆
-keep public class * extends android.preference.Preference # 保持哪些類不被混淆
-keep public class com.android.vending.licensing.ILicensingService # 保持哪些類不被混淆
-keepclasseswithmembernames class * { # 保持 native 方法不被混淆
native <methods>;
}
-keepclasseswithmembers class * { # 保持自定義控件類不被混淆
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {# 保持自定義控件類不被混淆
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity { # 保持自定義控件類不被混淆
public void *(android.view.View);
}
-keepclassmembers enum * { # 保持枚舉 enum 類不被混淆
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable { # 保持 Parcelable 不被混淆
public static final android.os.Parcelable$Creator *;
}
二、混淆實例
1、在proguard-project.txt裡面配置混淆後;
2、在project.properties中添加proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
3.混淆實例參考
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-ignorewarnings
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-dontwarn android.support.**
-dontwarn com.handmark.**
-dontwarn android.webkit.WebView
-keepclassmembers class youmengyou.bean.** {
public <fields>;
private <fields>;
public <init>();
public <init>(org.json.JSONObject);
*;
}
#保持 native 方法不被混淆
-keepclasseswithmembernames class * {
native <methods>;
}
#保持自定義控件類不被混淆
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
#保持自定義控件類不被混淆
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
#保持自定義控件類不被混淆
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
#保持枚舉類不被混淆
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclassmembers class **.R$* {
public static <fields>;
public static final int *;
}
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-keepattributes Exceptions,InnerClasses,Signature
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.IntentService
-keep public class * extends android.app.Service
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * extends android.widget.LinearLayout
-keep public class * extends android.widget.FrameLayout
-keep public class * extends android.widget.CheckBox
-keep class android.** { *; }
-keep public class javax.**
-keep class org.** { *; }
-keep class android.support.v4.** {*;}
-keep class android.support.v4.app.** { *; }
-keep class android.support.v4.view.** { *; }
-keep public class * extends android.support.v4.**
-keep public class android.webkit.**
#加解密
#-keep public class com.jfw.utils.ThreeDES
-keep interface android.support.v4.app.** { *; }
#下拉刷新
-keep class com.handmark.** { *; }
三、最後一步,打包、簽名
以前總以為Intellij idea 和android studio 在proguard-project.txt裡面設置以後,在編譯的時候就直接把代碼給混淆了,後面自己反編譯才發現,什麼都混淆,原來還有個操作沒做,需要在Generate Signed APK (簽名)的時候勾選上Run ProGuard 才行。
Android移動APP開發筆記——Cordova(PhoneGap)通過CordovaPlugin插件調用 Activity 實例,phonegapcordova引言
硅谷商城5--購物車商品選中和商品總價計算,5--購物車 1_商品總價格計算 ①在GovaffairPager類中設置 adapter = new GovaffairP
Linux內核系列—操作系統開發之進入32位保護模式,linux保護模式源碼如下: ; ========================================
Android開發學習之路-Android中使用RxJava,-androidrxjavaRxJava的核心內容很簡單,就是進行異步操作。類似於Handler和Async