Android project source code obfuscation Solution
Considering the code security, it is easy for others to steal their work. Today, I am eager to learn about Android code obfuscation. I want to help my friends who are learning android to avoid detours in the future.
Because my android project version is 1.6, Google added support for code obfuscation to 2.2 and later versions. However, code obfuscation can be performed in earlier versions, but you only need to manually configure it.
It is also quite simple. However, I encountered many problems during the configuration process. I found a lot of information online and did not solve my problem. Through constant exploration, we found a solution from a foreign website.
The solution is also very simple. The following is my solution.
1. Add proguard. Config = proguard. cfg directly to the default. properties File above sdk2.2.
2. In addition to the above settings, sdk2.2 also requires the following Configuration:
Copy the proguard. cfg file from other sdk2.2 and above to the project;
If there is no external jar package reference in the project, you only need to add a line-dontwarn to remove the warning;
If there is an external jar package reference, add two lines
-Dontwarn
-Dontskipnonpubliclibraryclassmembers
3. If an error persists, A. Check the SDK path with spaces. B. Change-dontpreverify to-dontoptimize.
------------------------------------------------------------- The following is the content of the proguard. cfg file -----------------------
-Optimizationpasses 5
-Dontusemixedcaseclassnames
-Dontskipnonpubliclibraryclasses
-Dontpreverify
-Verbose
-Optimizations! Code/simplification/arithmetic ,! Field /*,! Class/merging /*
-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>;
}
-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 *;
}
Note: QQ technology exchange group: add one if you are interested in 108614806.