Android code obfuscation notes

Source: Internet
Author: User

Android code obfuscation notes

After the apk for obfuscation is decompiled, the name and class names in the Code are changed to abcd, which is hard to understand.

Use code obfuscation, enable obfuscators, edit related files, and then package the signature;


In Version 2.3, the project contains the file proguard. cfg (you can add it manually if not)

Add: proguard. config = proguard. cfg

Content in the proguard. cfg file:

-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 
  ;}-keepclasseswithmembernames class * {    public 
   (android.content.Context, android.util.AttributeSet);}-keepclasseswithmembernames class * {    public 
    (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 *;}


The project files are project.propertiesand proguard-project.txt.

Open project. properties and uncomment the following line of code:

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

The default settings do not contain the optimization function. You can use the following settings to add the code optimization function:
# Proguard. config =$ {sdk. dir}/tools/proguard/proguard-android-optimize.txt: proguard-project.txt


Some editing rules for proguard-project.txt files:

-Libraryjars libs/android-support-v4.jar

-Libraryjars libs: loads third-party Jar packages

-Ignorewarnings: Remove warnings from code

-Keep class com. xxx. xxx .**

-Keep: keep non-obfuscation classes

This type of public method is retained and not obfuscated.
-Keep class com. xx. xx. Test {
Public *;

Protects specified class files and Class Members

-Keep class * implements android. OS. Parcelable {

Public static final android. OS. Parcelable $ Creator *;


Use the Eclipse tool to package the signature:

In Eclipse, right-click the project and choose> Android Tools

---> Export Signed Application Package... with RSA Digital Signature

---> Export Unsigned Application Package... without a digital signature

Select a method to follow the Wizard. The generated Apk is obfuscated.


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.