Android Studio implements code obfuscation, androidstudio
1, added in build. grandle, where rules are written in the proguard-rules.pro, you can also customize a file, replace it, such as eclipse commonly used proguard-project.txt
buildTypes { release { signingConfig signingConfigs.release minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' }}
2, add the following code in the proguard-rules.pro, basically covering all
-Optimizationpasses 5 # specify the compression level of the code-dontusemixedcaseclassnames # whether to use case-insensitive mixture-dontpreverify # Whether to perform pre-check-verbose # Whether to log-optimizations during obfuscation! Code/simplification/arithmetic ,! Field /*,! Class/merging/* # algorithm used for obfuscation-keep public class * extends android. app. activity # keep classes that are not Obfuscated-keep public class * extends android. app. application # keep classes that are not Obfuscated-keep public class * extends android. app. service # Do not confuse classes-keep public class * extends android. content. broadcastReceiver # keep classes that are not Obfuscated-keep public class * extends android. content. contentProvider # Do not confuse classes-keep public class * extends android. app. backup. backupAgentHelper # keep classes that are not Obfuscated-keep public class * extends android. preference. preference # keep classes that are not Obfuscated-keep public class com. android. vending. licensing. ILicensingService # Keep classes not Obfuscated-keepclasseswithmembernames class * {# Keep native METHOD not obfuscated native <methods> ;} -keepclasseswithmembers class * {# Keep the custom control class not obfuscated with public <init> (android. content. context, android. util. attributeSet);}-keepclasseswithmembers class * {# Keep the custom control class not obfuscated with public <init> (android. content. context, android. util. attributeSet, int);}-keepclassmembers class * extends android. app. activity {# Keep the custom control class from being confused with public void * (android. view. view);}-keepclassmembers enum * {# Keep The enum class from being confused public static ** [] values (); public static ** valueOf (java. lang. string);}-keep class * implements android. OS. parcelable {# Keep Parcelable not to be confused public static final android. OS. parcelable $ Creator *;}
3. When obfuscation code is implemented through Android Studio, the jar files in the lib directory have been added to the packaging script by default. Therefore, you do not need to manually add the jar files again. Otherwise, "java. io. IOException: The same input jar is specified twice "error.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.