Chinese InternetArticleThey are all crawlers. They are always the same. This time, I tested this successfully.
Http://blog.csdn.net/zxciop110/article/details/8707550 in combination with my example
As a technical developerSource codeTo prevent reverse engineering from being exposed.CodeObfuscation. Code obfuscation is also called a flower command.ProgramCode is equivalent to a function, but it is difficult to read and understand the form of behavior, code obfuscation can be used for the program source code, can also be used for the intermediate code compiled by the program. Today, I will focus on how to confuse the android project code.
First, I will explain the code obfuscation of the APK file (that is, the application installation file) generated after the android project is compiled successfully, because third-party personnel can decompress the APK file and obtain the project source code from it, the protection of the APK file is crucial. Anyone who has developed Android knows that when creating a new Android project, we need to select the API version for this project, google provides different encapsulation methods for different api versions. Here we use Version 2.3 as the core point. Careful personnel should be able to find that there is a folder named proguard under the tools directory of Android-SDK, which is currently the most commonly used code obfuscation tool in the Java field.
OK! Success,
I believe that students who have never touched on code obfuscation are certainly unfamiliar with this file, but what I want to tell you is, yes, you guessed it! It is the script file of proguard obfuscation code. The great Google has helped us to do this well. The only thing we need to do is compile our own project and generate the APK file; remember what I mentioned earlier? Hosts file? The answer is obviously no, because Google has encapsulated code obfuscation script files for us since Version 2.3. So what should we do for versions earlier than 2.3? Here we have two steps to do this. First, go to 2.3to copy a copy of The proguard-project.txt file in the previous project and copy it to the root directory of the current project. Then, open the project in the current project. properties (the old version is default. properties) file, add such a line of code at the end of the file: proguard.config1_proguard-project.txt, save the file, and then compile your project again, then the generated APK file has been mixed up with the code.
After introducing the code obfuscation of the APK file, let's talk about another situation. The product we need to deliver to a third party is not an APK file, instead, we use a complete Android project as a library for their use. How should we obfuscation the code? First, we need to confirm that all the source code in the project is. the Java file is packaged into a jar package. class file), next we need to do is to confuse the jar package, the script file writing specifications are as follows:
- Injars androidtest . Jar // Address of the jar package - Outjars out // Output address - Libraryjars'D: \ Android-SDK-Windows \ platforms \ Android-9 \ Android. Jar' // The jar of the referenced library, used to parse the jar class specified by injars - Optimizationpasses 5 - Dontusemixedcaseclassnames- Dontskipnonpubliclibraryclasses - Dontpreverify // No pre-check - Verbose - Optimizations ! Code/ Simplification / Arithmetic ,! Field/*,! Class/merging/*-keep public class * extends android. app. activity // remain unchanged without obfuscation-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. P Reference. preference-keep public class COM. android. vending. licensing. ilicensingservice-keep public abstract interface COM. asqw. android. listener {public protected & lt; Methods & gt; // do not confuse all methods}-keep public class COM. asqw. android {public void start (Java. lang. string); // do not confuse this method}-keepclasseswithmembernames class * {// protect the name of the specified class and class member, if all specified class members are present (after the compression step) Native & lt; Methods & gt ;}- keepclasseswithmembers C Lass * {// protects the specified class and class members, but the condition is that all specified classes and Class Members must exist. Public & lt; init & gt; (Android. content. context, android. util. attributeset);}-keepclasseswithmembers class * {public & lt; init & gt; (Android. content. context, android. util. attributeset, INT);}-keepclassmembers class * extends android. app. activity {// protects the members of a specified class. If this class is protected, it will better protect the public void * (Android. view. view);}-keepclassmembers Enum * {public static ** [] values (); public static ** valueof (Java. lang. string);}-keep class * implements android. OS. parcelable {// protect the public static final android. OS. parcelable $ creator *;}
When obfuscation of Android code, we cannot confuse the subclass of activity, service, and broadcastrevicer. Otherwise, the resource file will be lost. at the end of pro, open the proguard folder in the SDK and find proguardgui under the bin directory. BAT file, double-click to open,
Click the "load configuration" button to import the script file, and click "Next". When the prompt "processing completed successfully" is displayed! It indicates that our jar package has been successfully obfuscated. Then let's take a look at the content in our jar package:
If you deliver such a project to a third party, you will never worry about the confidentiality of the source code!