How Android prevents the APK program from being recompiled

Source: Internet
Author: User

 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?
  1. -optimizationpasses 5
  2. -dontusemixedcaseclassnames
  3. -dontskipnonpubliclibraryclasses
  4. -dontpreverify
  5. -verbose
  6. -optimizations!code/simplification/arithmetic,!field/*,!class/merging/*
  7. -keep public class * extends Android.app.Activity
  8. -keep public class * extends Android.app.Application
  9. -keep public class * extends Android.app.Service
  10. -keep public class * extends Android.content.BroadcastReceiver
  11. -keep public class * extends Android.content.ContentProvider
  12. -keep public class * extends Android.app.backup.BackupAgentHelper
  13. -keep public class * extends Android.preference.Preference
  14. -keep public class Com.android.vending.licensing.ILicensingService
  15. -keepclasseswithmembernames class * {
  16. Native <methods>;
  17. }
  18. -keepclasseswithmembernames class * {
  19. Public <init> (Android.content.Context, Android.util.AttributeSet);
  20. }
  21. -keepclasseswithmembernames class * {
  22. Public <init> (android.content.Context, Android.util.AttributeSet, int);
  23. }
  24. -keepclassmembers enum * {
  25. public static **[] values ();
  26. public static * * VALUEOF (java.lang.String);
  27. }
  28. -keep class * Implements Android.os.Parcelable {
  29. public static final Android.os.parcelable$creator *;
  30. }

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?
  1. # This file was automatically generated by Android Tools.
  2. # Do not modify the This file--YOUR changes'll be erased!
  3. #
  4. # This file must is checked in Version Control Systems.
  5. #
  6. # to customize properties used by the Ant build system use,
  7. # "Build.properties", and override values to adapt the script to your
  8. # project structure.
  9. # Project Target.
  10. target=android-9
  11. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.