Android Anti-compilation and prevention against being recompiled

Source: Internet
Author: User

Spring Trade Software Studio original, original address: http://www.svch0st.com/cont.asp?id=38

Android apps are developed in the Java language, so it's easy to decompile almost the original code. Also because of this feature, many people in the Android app will like to decompile the other people write the program, and then move for their own use, although very unethical, but this is an effective way to improve the speed of software development. But in a different way, if it is written by their own code is stolen, this is not very good for themselves, so learning how to prevent their own code theft is also a very important topic. The Android app installation file is a file with the. apk file name, which can be executed directly in the Android environment, and the app will be installed. To put an app on Google Play, you must first export the Android project to a signed (signed) APK file. Upload this apk file to Google Play and send it out. Once the app is on the shelves, other users can install the app directly from Google Play. Obviously, it's dangerous to provide an apk file to someone else to install the app, because the APK file can decompile the original code as long as it passes through a simple step (which is mentioned later). But if you think it's safe to put apps on Google Play, it's a big mistake, because apps installed from Google Play have a way to get their apk files.

Anti-compilation Android program

The first thing to do is to get the APK file for the Android app and then use "dex2jar" to turn it into a jar file.

https://code.google.com/p/dex2jar/

Dex2jar is used under the command column, the command format is as follows:

d2j-dex2jar.sh apk Path

650) this.width=650; "src=" Http://www.svch0st.com/up_files/2015714/2015714134928514926.png "width=" 650 "style=" border:none;padding:0px;margin:0px;vertical-align:top; "/>

After executing the command, wait a moment, the jar file is generated.

Then follow this article to decompile the jar file.

prevent Android programs from being recompiled

The way to decompile the Android program can not be learned, but the way to prevent the anti-compilation must be!
Android Proguard

The Android SDK provides proguard to protect and optimize the Android app's installation files. As a competent Android programmer, be sure to use Proguard to protect code before the Android app is posted or on the shelves to avoid the program being stolen by people with a heart.
Enable Proguard

In the Android project root directory, there is a "project.properties" file, find the following string, and remove the previous "#", you can enable Proguard.

    # Proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

This line of text means to tell Eclipse to use Proguard to confuse code when compiling Android, and to specify a confusing parameter profile. The preset Android project adds "#" at the beginning, indicating that this line of text is annotated, that is, the Proguard is not turned on.


Using Proguard

After you enable Proguard, you will automatically confuse the code by using the Android Export tool to export the project. No further action is required.


Issues that you may encounter when you enable Proguard

Because some programs can not be confused, such as the use of methods such as "class.forname" to call the suite. You can keep the specified code from being confused by modifying the Proguard profile "proguard-project.txt" in the Android project directory by adding the-keep parameter. Usually the-dontwarn parameter will also be used with-keep, the purpose is to let Proguard do not check the specified class under the code error (of course, if there are errors and not later).

There are a number of programs that use the Proguard, and then the type conversion error occurs, you can add "-keepattributes signature" parameters, retain the program's signature.

The following is a set reference for Proguard-project.txt:

-keep class com.google.** {*;}-dontwarn com.google.**-keep class com.facebook.** {*;}-dontwarn com.facebook.**-kee P class org.apache.** {*;}-dontwarn org.apache.**-keepattributes Signature

After the confusing code, if it is decompile, no one can understand!


Android Anti-compilation and prevention against 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.