"Turn" anti-compilation and anti-compilation of Android development

Source: Internet
Author: User

Anti-compilation and anti-compilation of Android development

Preventing anti-compilation is a required course for every programmer, because when you work hard to develop an application, be someone else rinsed to the anti-compilation, what an embarrassing thing ah. So how to prevent anti-compilation Ah? This is a way to prevent decompile by using Google Android's own code. The Art of War is good: "Tse Baizhanbudai", so before we explain how to prevent anti-compilation, let's look at how to decompile an application.

First, anti-compilation Android application experiment environment:

Windows8.1 Enterprise Edition, dex2jar-0.0.9.9

Anti-compilation Toolkit:

Android Anti-compile toolkit (upgrade)

1. decompile the APK to get the Java source code specific steps:

1) First change the apk file suffix to zip and unzip, get the Classes.dex, it is Java file compilation and then through the DX tool packaging, will classes.dex copy to Dex2jar.bat directory dex2jar-0.0.9.9 folder.

Under command line, navigate to the directory where the Dex2jar.bat is located, run

Dex2jar.bat Classes.dex

Generate Classes_dex2jar.jar

2) Enter the Jdgui folder double-click Jd-gui.exe, open the above generated jar package Classes_dex2jar.jar, you can see the source code, such as:

2. Set the APK to decompile the source code and pictures, XML configuration, language resources, and other files of the generated program in the specific steps:

1) Download the Anti-compilation toolkit above, open the apktool1.4.1 folder under the Apk2java directory, containing three files: Apktool.jar, Aapt.exe,apktool.bat,

Note: The Apktool_bk.jar inside is the old version of the backup, preferably with the latest Apktool.jar

Under command line, navigate to the Apktool.bat folder, and enter the following command:apktool.bat d-f abc123.apk abc123

Such as:

, Apktool.bat command line explanation: Apktool.bat d-f [apk file] [output folder]

[HTML]View Plaincopy
  1. <?xml version= "1.0" encoding= "Utf-8"?>
  2. <manifest android:versioncode= "1" android:versionname= "1.0" package= "Com.jph.recorder"
  3. Xmlns:android= "Http://schemas.android.com/apk/res/android" >
  4. <USES-SDK android:minsdkversion= "8" android:targetsdkversion= "/>"
  5. <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
  6. <uses-permission android:name= "Android.permission.RECORD_AUDIO"/>
  7. <uses-permission android:name= "Android.permission.VIBRATE"/>
  8. <uses-permission android:name= "Android.permission.SEND_SMS"/>
  9. <application android:theme= "@style/apptheme" android:label= "@string/app_name" android:icon= "@drawable/ic_ Launcher "android:allowbackup=" true ">
  10. <activity android:label= "@string/app_name" android:name= "Com.jph.recorder.Recorder" >
  11. <intent-filter>
  12. <action android:name= "Android.intent.action.MAIN"/>
  13. <category android:name= "Android.intent.category.LAUNCHER"/>
  14. </intent-filter>
  15. </activity>
  16. <activity android:label= "@string/show_recordfile" android:name= "Com.jph.recorder.ShowRecordFiles"/>
  17. <activity android:theme= "@android: Style/theme.dialog" Android:name= ". Aboutactivity "/>
  18. <activity android:label= "@string/feedback_label" Android:name= ". Feedbackactivity "/>
  19. <service android:name= "Com.jph.recorder.RecordService"/>
  20. </application>
  21. </manifest>



To repackage the finished file into an apk, it is easy to enter Apktool.bat b abc123(you compiled the folder), the command is as follows:

After packaging the apk file under directory C:\HelloAndroid, two folders were generated:

Build

Dist

wherein, the package generated helloandroid.apk, in the above Dist folder, Ok

3. Graphical anti-compilation apk

Step one or two above describes the command-line anti-compilation apk, which now provides a graphical anti-compilation tool: Androidfby

First, download the Anti-compilation toolkit above, open the Androidfby directory, and double-click the Android Anti-compilation tool. exe to browse to the APK file you want to decompile.

Second, prevent the application from being decompile

Let's start by describing what is code obfuscation:

Code obfuscation, also known as the flower Directive, is the act of translating the Code of a computer program into a functionally equivalent, but difficult-to-read and understandable form of obfuscated. Code obfuscation can be used for program source code, or for program-compiled intermediate code. A program that executes code obfuscation is called a code-obfuscation. There are many different kinds of code obfuscation.

Rewrite the names of various elements in the code, such as variables, functions, and classes, into meaningless names. For example, a single letter, or a short, meaningless combination of letters, or even a symbol such as "__", makes it impossible for a reader to guess its use by name. Rewrite some of the logic in the code, turning it into a functionally equivalent, but more difficult form to understand. For example, the For loop is rewritten as a while loop, the loop is rewritten as recursive, the intermediate variable is streamlined, and so on. Disrupts the formatting of the code. For example, delete a space, squeeze multiple lines of code into one line, or break a line of code into multiple lines, and so on.

Before and after confusing the code to decompile the comparison:

Hint: A friend of Hearts can find: confusing after generating the apk file is much smaller than the APK file generated before the confusion. This not only reduces the size of the project but also improves the execution speed of the code. Such as:

Specific steps:

1) See if there are any proguard.cfg in the project.

If not, download from this:

Proguard.cfg

The proguard.cfg is then copied to the project.

2) Add the Project.Properties file in the project: Proguard.config=proguard.cfg

3) then sign your application according to the normal signature, the generated apk after the anti-compilation will be very different from the source code.

Note: It is important to sign the application through the normal signing method, the APK file generated in the project Bin directory is the way of using the system default signature, not to achieve the effect of the code mixed.

If the signature is unsuccessful, look down:

4) However, you will encounter a lot of problems in this step, the signature is not successful at all. For example: ① If the project introduces the Android-support-v4 Jar class Library, then in the project packaging confusion, there will be error prompts you: "may need to specify additional library jars (using '- Libraryjars '). ② references to third party packages and other issues

If the project introduces the Android-support-v4 Jar class Library, then you will be in the back of proguard.cfg and add the following:

-libraryjars/android-support-v4.jar

-dontwarn android.support.v4.**

-keep class android.support.v4.** {*;}

-keep public class * extendsandroid.support.v4.**

-keep public class * Extendsandroid.app.Fragment

Then you pack it up and you should be able to build the APK installer properly.

If it appears: "Class 1 can ' t find referenced class 2" literally means that Class 1 cannot find a reference to class 2; it will suggest you: "The need to specify additional library jars (using ' -libraryjars '). ";

The need to use-libraryjars plus third-party libraries used in the project is OK.

Example:-libraryjars/android-support-v4.jar

Note: The reference here is the current project's root directory (you can also configure other directories), that is, you want to put a third-party jar in the current directory, or you will be warned that the jar file cannot be found!

If it appears: Can ' t find superclass or interfaceandroid.os.parcelable$classloadercreator, in which case it is possible to use-dontwarncom.xx.yy.**, No warning of errors.

Note: Use this method to ensure that you do not use the class in this library! Or they'll throw classnotfoundexception!.

If the class is actually used in the project, it is not possible to use the above method. Add another item at this time:-keep class com.xx.yy.** {*;}, so that the current class is not confused.

Summarize:

For cases where a third-party package is referenced, you can avoid packaging errors in the following ways:

-libraryjars/aaa.jar

-dontwarn com.xx.yy.**

-keep class com.xx.yy.** {*;}

Finally packaging success, I wish you a successful confusion encryption!

"Turn" anti-compilation and anti-compilation of Android development

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.