Android Simple Code obfuscation

Source: Internet
Author: User

Android's code obfuscation is a knowledge that developers need to know to prevent anti-compilation of Android apps. Because most Android programs are developed in the Java language, and Java code is easy to decompile, the confuse right of Android code is often necessary in order to apply certain security to the Android application code.

Learn about the anti-compilation of Android before you understand the code obfuscation. The anti-compilation of Android requires two tools Dex2jar and Jd-gui.

1. Anti-compilation of code

After the two tools are ready, unzip the apk file directly. In the extracted file, copy the Classes.dex to the Dex2jar folder. Input command:dex2jar.bat classes.dex , enter. Classes_dex2jar compressed files are generated in the Dex2jar folder. Open the file with Jd-gui to see the source code for the Android app.

2. Code obfuscation

Add proguard.cfg. File to Android project. Add Proguard.config=proguard.cfg to Project.Properties.

-ignorewarnings-libraryjars libs/android-support-v4.jar-libraryjars libs/gson-2.2.4.jar-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 Androi D.content.broadcastreceiver-keep public class * extends Android.content.contentprovider-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 *;}
proguard.cfg

3. Project Packaging

Right-click Project, select Androidtools-export unsinged application package. Decompile the packaged apk.

As you can see, the code has been compiled. The unsigned apk package is not able to be installed, and you need to sign the APK.

Android Simple Code obfuscation

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.