+2
Viết proguard cho Android như nào?
Mình thường gặp rắc rối khi viết proguard cho 1 project Android Nó thường ko release được hoặc chạy bị crash hoặc ko lấy được dữ liệu từ api
Mọi người có kinh nghiệm hoặc tool nào về viết và debug proguard cho mình xin ít ạ Thanks
Thêm một bình luận
1 CÂU TRẢ LỜI
+11
Kinh nghiệm thì a ko có nhưng có file proguard gia truyền. Mặc định cho các project a đang dùng, ngoài ra có dùng thêm lib nào nữa thì thêm vào. thấy nó chạy mà ko có lỗi nào Khi build xong nhớ lưu lại file maping để có crash còn map ngược lại code khi chưa obfucated
#================================= DEFAULT PROGUARD RULES =========================================#
#Use 5 step of optimization
-optimizationpasses 5
#When not preverifing in a case-insensitive filing system, such as Windows. This tool will unpack your processed jars,(if using windows you should then use):
-dontusemixedcaseclassnames
#Specifies not to ignore non-public library classes. As of version 4.5, this is the default setting
-dontskipnonpubliclibraryclasses
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
#Specifies to write out some more information during processing.
#If the program terminates with an exception, this option will print out the entire stack trace, instead of just the exception message.
-verbose
#Keep classes that are referenced on the AndroidManifest
-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.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
#Compatibility library
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
#To remove debug logs:
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** w(...);
}
#Maintain java native methods
-keepclasseswithmembernames class * {
native <methods>;
}
#To maintain custom components names that are used on layouts XML:
-keep public class * extends android.view.View {
public <init>(android.content.Context);
}
-keep public class * extends android.view.View {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keep public class * extends android.view.View {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
#Maintain enums
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#To keep parcelable classes (to serialize - deserialize objects to sent through Intents)
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
#Keep the R
-keepclassmembers class **.R$* {
public static <fields>;
}
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-dontwarn android.support.v4.**