How Android prevents APK programs from being decompile

Source: Internet
Author: User
Tags config extend

As Android application developers, have to face an embarrassing situation, is their own hard to develop the application can be easily compiled by others.

Google also 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, others even decompile your APK package, will only see some difficult to understand the code, so as to protect the role of the Code.

The following specifically say how to let SDK2.3 under the Proguard.cfg file work, first look at the contents of Android-sdk-windows\tools\lib\proguard.cfg:

-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 * Extend s android.app.service-keep public class * extends Android.content.broadcastreceiver-keep public class * Extend  s 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 the activity, Service, application, Broadcastreceiver, ContentProvider such as basic components and com.android.vending.licensing.ILicensingService,

All the native variable names and class names are retained, and all classes are partially set up with a fixed parameter format constructor, enumeration, and so on. (For more information, refer to the examples and comments in <proguard_path>/examples.) )

The simple way to make proguard.cfg work is simply to add a "proguard.config=proguard.cfg" to the Default.properties file that eclipse automatically generates.

The complete default.properties file should read as follows:

# This file was 

automatically generated by Android Tools.     
# don't modify this file--YOUR CHANGES would 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 T He script to your     
# project structure.     
         
# Project Target.     
Target=android-9     
proguard.config=proguard.cfg

Done, the normal compilation of signatures can prevent the code from being decompile. The code that is apk by code obfuscation should resemble the following effect and is difficult to read:

If you are using the SDK version before 2.3, it doesn't matter, copy the Proguard.cfg file to the project, and then do the same thing.

Related Article

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.