http://blog.csdn.net/ithomer/article/details/6727640Category: Android2011-08-28 23:07 67210 people read reviews Collection report Androidclasspropertiestoolsapplication
As an Android app developer, you have to face an awkward situation where your hard-to-develop apps can be easily recompiled by others.
Google seems to have found the problem, starting with SDK2.3 we can see a Proguard folder under Android-sdk-windows\tools\
Proguard is a Java code obfuscation tool, through proguard, even if the other people decompile your APK package, you will only see some difficult to understand the code, so as to achieve the role of protection Code.
The following specific say how to let SDK2.3 under the Proguard.cfg file function, first look at android-sdk-windows\tools\lib\proguard.cfg content:
[HTML]View Plaincopyprint?
- -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 * extends Android.app.backup.BackupAgentHelper
- -keep public class * extends Android.preference.Preference
- -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, the confusion retains the inheritance from activity, Service, application, Broadcastreceiver, Basic components such as ContentProvider and Com.android.vending.licensing.ILicensingService,
All the native variable names and class names are preserved, and in all classes, constructors, enumerations, and so on, are set in fixed parameter format. (Please refer to the examples and comments in <proguard_path>/examples for more information.) )
The way to make proguard.cfg work is simply to add a "proguard.config=proguard.cfg" to the Eclipse Auto-generated default.properties file.
The complete default.properties file should be as follows:
[HTML]View Plaincopyprint?
- # This file was automatically generated by Android Tools.
- # Do not modify the This file--YOUR changes'll be erased!
- #
- # This file must is checked in Version Control Systems.
- #
- # to customize properties used by the Ant build system use,
- # "Build.properties", and override values to adapt the script to your
- # project structure.
- # Project Target.
- target=android-9
- proguard.config=proguard.cfg
Done, the normal compilation signature will prevent the code from being recompiled. Decompile code-confusing APK get code should look like the following effect, it is difficult to understand:
If you're using the SDK version before 2.3, it's okay to copy the above proguard.cfg file into your project and do the same thing.
Blog Star selection, please vote for me:
http://vote.blog.csdn.net/blogstaritem/blogstar2013/sunboy_2050
How Android prevents the APK program from being recompiled