Current location - Health Preservation Learning Network - Slimming men and women - Android code confusion and how to judge whether an apk code is confused.
Android code confusion and how to judge whether an apk code is confused.
1, principle of program protection

Java code is compiled into a binary class file, which can also be decompiled into source code. In addition to comments, other codes can basically be seen. In order to prevent the disclosure of important codes, we often need to be confused, that is, change the names of java elements such as method names, variable names, class names and package names. To unexpected names, so that the code structure remains unchanged, you can run, but it is difficult to understand the code architecture. Proguard played such a role:

First, it can analyze the structure of a group of classes, and then confuse the java elements that can be confused in these class files according to the user's configuration.

Second, delete the invalid code.

Thirdly, optimize the code (apk and zipalign optimized by adt plug-in).

By default, proguard confuses all codes, but in the following cases, you can't change the name of a java element, otherwise it will cause a program error.

First, where reflection is used (api in android is often commented out by @hide, and developers need to use reflection when calling corresponding methods).

Second, when the code of the app depends on the interface of the system, such as the callback method called by the system code, this method is more complicated.

Third, configure the java element name in the configuration file.

So when using proguard, we need to have a configuration file to tell proguard which java elements can't be confused.

2.proguard configuration

-dontwarn default proguard will check whether each reference is correct, but some classes in third-party libraries are often not used and the references are incorrect. If it is not configured, the system will report an error.

Classes and class members specified by -keep are kept as entries.

Class members specified by -keepclassmembers are reserved.

If the specified class member exists, the class and class member specified by -keepclasswithmembers are retained.