How does Android prevent the apk program from being decompiled (respect for labor results)

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 there is a proguard folder added under android-sdk-windows \ tools \.

Proguard is a java code obfuscation tool. With proguard, even if you decompile your apk package, others will only see some ugly code to protect the code.

The following describes how to make the proguard. cfg file under SDK2.3 take effect. Let's take a look at the content of android-sdk-windows \ tools \ lib \ proguard. cfg:Copy codeThe Code is as follows:-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 *;
}

From the script, we can see that the obfuscation retains the basic components inherited from Activity, Service, Application, BroadcastReceiver, ContentProvider, and com. android. vending. licensing. ILicensingService,
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 .)

It's easy to make proguard. cfg take effect. Add "proguard. config = proguard. cfg" to the default. properties file automatically generated by eclipse.

The complete default. properties file should be as follows:Copy codeThe Code is 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,
# "Build. properties", and override values to adapt the script to your
# Project structure.
# Project target.
Target = android-9
Proguard. config = proguard. cfg

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