Android Application Obfuscation

Source: Internet
Author: User

 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:

  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 com. Android. Vending. Licensing. ilicensingservice
  13. -Keepclasseswithmembernames class *{
  14. Native <Methods>;
  15. }
  16. -Keepclasseswithmembernames class *{
  17. Public <init> (Android. content. Context, Android. util. attributeset );
  18. }
  19. -Keepclasseswithmembernames class *{
  20. Public <init> (Android. content. Context, Android. util. attributeset, INT );
  21. }
  22. -Keepclassmembers Enum *{
  23. Public static ** [] values ();
  24. Public static ** valueof (Java. Lang. String );
  25. }
  26. -Keep class * implements Android. OS. parcelable {
  27. Public static final Android. OS. parcelable $ creator *;
  28. }

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:

  1. 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:

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.