2.3sdk has two new features:
1.When I first installed 2.3, I checked the SDK directory and found that a folder "proguard" was added under <sdk_path> \ tools, as shown in, I was wondering if Google had finally taken proguard into consideration. Theoretically, obfuscation of Java is acceptable, but the key lies in how to compile the proguard obfuscation script.
2. After sdk2.3 is used, a file "proguard. cfg" will be added to the new project compared with the previous one ". The proguard script is required for obfuscation.
For example:
The Code is as follows:
- -Optimizationpasses 5
- -Dontusemixedcaseclassnames
- -Dontskipnonpubliclibraryclasses
- -Dontpreverify
- -Verbose
- -Optimizations! Code/simplification/arithmetic ,! Field /*,! Class/merging /*
- -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 com. Android. Vending. Licensing. ilicensingservice
- -Keepclasseswithmembernames class *{
- Native <Methods>;
- }
- -Keepclasseswithmembernames class *{
- Public <init> (Android. content. Context, Android. util. attributeset );
- }
- -Keepclasseswithmembernames class *{
- Public <init> (Android. content. Context, Android. util. attributeset, INT );
- }
- -Keepclassmembers Enum *{
- Public static ** [] values ();
- Public static ** valueof (Java. Lang. String );
- }
- -Keep class * implements Android. OS. parcelable {
- Public static final Android. OS. parcelable $ creator *;
- }
As you can see from the script, obfuscation retains the basic components inherited from activity, service, application, broadcastreceiver, contentprovider, and so on.
All native variable names and class names are retained. All classes Use constructors with fixed parameter formats, such as enumeration. (For more information, see examples and comments in <proguard_path> \ examples .)
Well, it's almost done. Let's take a look at how to generate a obfuscated APK. Please note that the new features of the SDK are available in the document, so the document is very important.
View the sdk2.3 document and go to "<androidsdk_path>/docs/GUIDE/developing/tools/proguard.html".Enabling proguard"Is described as follows:
- To enable proguard so that it runs as part of an ant or eclipse build, set the proguard. config property in the <project_root>/default. properties file. the path can be an absolute path or a path relative to the project's root.
Okay, so do it.
Add the following phrase "proguard. Config = proguard. cfg" to "Default. properties" of the project, for example:
In this way, the ADT obfuscation operation has been set. The next step is the normal packaging and signature ..
It is the notepad that comes with the SDK demo: