Android Java obfuscation (proguard)

Source: Internet
Author: User
<span id="Label3"></p>Android java obfuscation (proguard) (rpm) Proguard Introduction<p><p>Proguard is a very well-known open source project on Sourceforge. Website website Is: http://proguard.sourceforge.net/.</p></p><p><p>Java bytecode is generally very easy to decompile. In order to protect the Java source code very well, We often confuse the compiled class File. The main function of Proguard is to Confuse. of course, It can also reduce the size of bytecode, optimization, and so on, but those for us is a secondary function.</p></p><p><p>A quote from the official Proguard is:</p></p><p><p>Proguard is a free Java class file shrinker, optimizer, obfuscator, and Preverifier. IT detects and removes unused classes, fields, methods, and Attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using a short meaningless names. Finally, it preverifies the processed code for Java 6 or for Java Micro Edition.</p></p><br>Android Eclipse Development Environment and Proguard<p><p>Before Android 2.3, It was very inconvenient to confuse Android code by manually adding Proguard for code Obfuscation. After 2.3, Google has added this tool to the Sdk's Toolset. Specific Path: Sdk\tools\proguard. When you create a new Android project, a proguard configuration file proguard.cfg appears under the root path of the project Directory. In other words, we can use the simple configuration to confuse Android engineering directly with Proguard in our Elipse project.</p></p><p><p>The exact steps to confuse are very simple. first, we need to add a sentence in the project description file Default.properties to enable Proguard. As shown Below:</p></p><p><p></p></p><p><p></p></p>1 # This file was automatically generated by Android Tools.<br>2 # Do not modify the This File--YOUR changes'll be erased!<br>3 #<br>4 # This file must is checked in Version Control Systems.<br>5 #<br>6 # To customize properties used by the Ant build system use,<br>7 # "build.properties", and override values to adapt the script to your<br>8 # project Structure.<br>9 # Indicates whether an APK should is generated for each Density.<br>Ten Split.density=false<br># Project Target.<br>Target=android-10<br>Proguard.config=proguard.cfg<br>14<p><p><br>In this way, the Proguard can be Used. When we export the application package normally through Android tools, Proguard is automatically enabled and the optimization confuses your Code.<br><br><span lang="EN-US"></span></p></p><p><p></p></p><p align="center"><p align="center"></p></p><p><p><br>After the export is successful, you can reverse-compile to see the effect of Confusion. Some class names, method names, variable names, and so on, all become meaningless letters or numbers. Prove the confusion is successful!</p></p><br>PROGUARD.CFG Configuration<p><p>Think about the confusing results a little bit, and you'll find that if the names of the classes, methods, and variables that are provided to the outside are changed, the functionality of the program itself will not be implemented PROPERLY. So how does proguard know which things can be renamed, and which ones cannot be changed?</p></p><p><p>This is configured by the Proguard.cfg File. The default auto-generated proguard.cfg in Android Engineering has been configured for android, and we've opened this configuration File. The content might look like this:</p></p><p><p></p></p><p><p></p></p>1-optimizationpasses 5<br>2-dontusemixedcaseclassnames<br>3-dontskipnonpubliclibraryclasses<br>4-dontpreverify<br>5-verbose<br>6-optimizations!code/simplification/arithmetic,!field/*,!class/merging/*<br>7-keep public class * extends Android.app.Activity<br>8-keep public class * extends Android.app.Application<br>9-keep public class * extends Android.app.Service<br>10-keep public class * extends Android.content.BroadcastReceiver<br>11-keep public class * extends Android.content.ContentProvider<br>12-keep public class * extends Android.app.backup.BackupAgentHelper<br>13-keep public class * extends Android.preference.Preference<br>14-keep public class Com.android.vending.licensing.ILicensingService<br>15<br>16-keepclasseswithmembernames class * {<br>Native <methods>;<br>18}<br>19<br>20-keepclasseswithmembernames class * {<br>Public <init> (android.content.Context, android.util.AttributeSet);<br>22}<br>23<br>24-keepclasseswithmembernames class * {<br>Public <init> (android.content.Context, android.util.AttributeSet, int.);<br>26}<br>27<br>28-keepclassmembers enum * {<br>public static **[] values ();<br>public static * * ValueOf (java.lang.String);<br>31}<br>32<br>33-keep class * Implements Android.os.Parcelable {<br>public static final Android.os.parcelable$creator *;<br>35}<br>36<p><p><br>It retains the main inheritance from activity, application, Service, broadcastreceiver, contentprovider, backupagenthelper, Subclasses of preference and Ilicensingservice. Because these subclasses can be called Externally.</p></p><p><p>In addition, it retains classes that contain the native method, constructors that are constructed from XML (typically a subclass of view), values and valueof static methods in enumeration types, and cross-process data classes that inherit Parcelable.</p></p><p><p>In a real project, it is possible that Google's auto-generated configuration is not up to our confusing Work. so, we often need to write some Proguard configuration Ourselves. This information is described in detail in the usage manual-i of the official Website. We can look into it.</p></p><br>Resources<p><p>"proguard official"</p></p><p><p>"Android 2.3 Code Obfuscation Proguard technology introduction"</p></p><p><p>Android Java obfuscation (proguard)</p></p></span>

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.