How to Prevent the APK from being decompiled in Android

Source: Internet
Author: User

As an Android app developer, you have to face an embarrassing situation: applications that have worked hard to develop can be decompiled easily by others. Google also seems to have discovered this problem. From sdk2.3, we can see that a proguard folder is added under Android-SDK-Windows/tools/, and proguard is a Java code obfuscation tool, with proguard, even if you decompile your APK package, you will only see some ugly code to protect the code.

Let's talk about how to make the proguard. cfg file under sdk2.3 take a look at the content of proguard. cfg:

-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontpreverify-verbose-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*-keep public class * extends public class * extends public class * extends public class * extends android.content.BroadcastReceiver-keep public class * extends android.content.ContentProvider-keep public class 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 shown in the script, obfuscation retains the basic components inherited from activity, service, application, broadcastreceiver, contentprovider, and COM. android. vending. licensing. ilicensingservice, retains all native variable names and class names, And some of all classes Use constructors with fixed parameter formats, enumerations, and so on. (For more information, see examples and comments in <proguard_path>/examples .)

Make proguard. CFG works very easily, that is, the default automatically generated in eclipse. add "proguard. config = proguard. CFG, complete default. the properties file should be as follows:

# This file is automatically generated by Android Tools.# Do not modify this file -- YOUR CHANGES WILL BE ERASED!## This file must be checked in Version Control Systems.## To customize properties used by the Ant build system use,# "", and override values to adapt the script to your# project structure.# Project

After the signature is compiled properly, the code can be decompiled. The Code produced by the decompiled APK after code obfuscation should be similar to the following, which is hard to understand:

If you are using an SDK version earlier than 2.3, copy the above proguard. cfg file to the project and perform the same operation.

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