Android Obfuscation parameter description go to

Source: Internet
Author: User

About confusing compilation is also mainly from the online learning, decided to summarize the online, for everyone to study together, research, the main things are netizens wrote, I learned here, the end of the article is the original address of the Netizen;  1, what is confusing compilation   Proguard is a free Java class file for compression, optimization, and obfuscation. It detects and removes unused classes, fields, methods, and properties. It removes useless instructions and uses bytecode to get maximum optimization. It uses meaningless names to rename classes, fields, and methods. The Proguard is used to: 1. Create compact code documents for faster network transmission, Fast loading and smaller memory footprint. 2. It is difficult to use reverse engineering to create programs and libraries. 3. So it can delete code from the source file that is not called in 4. Take advantage of the fast loading of JAVA6 to detect and return the class files that exist in Java6 in advance .  Proguard supports those kinds of optimizations: In addition to the useless classes, fields and methods that are removed by the compression operation, Proguard can also provide performance optimizations at the bytecode level, with internal methods: 1 Constant expression Evaluation 2 delete unnecessary field Access 3 Delete unnecessary method calls 4 Delete unnecessary branch 5 Remove unnecessary comparisons and instanceof validation 6 remove unused Code 7 remove write-only segment 8 Remove unused method parameter 9 a variety of peephole optimizations like Push/pop simplification 10 add the static and final modifiers to the class if possible 11 If possible, add private to the method, static and final modifier 12 to make the Get/set method inline if possible 13 when the interface has only one implementation class, replace it 14 The actual optimization effect of the selective delete log code is dependent on your code and the virtual machine that executes the code. A simple virtual machine is more efficient than an advanced virtual machine with a complex JIT compiler. In any case, your bytecode will get smaller.   Unsupported technologies that need to be optimized:  1 makes non-final constant fields inline 2 like the Get/set method makes other methods inline 3 move a constant expression outside of the loop 4 optimizations that require escape ANALYSIS  2, start the obfuscation feature in Android (confusion about Eclipse, a whole bunch of online, no explanation here)        Add the Proguard.flags file to the project directory under Confusion (package/apps/), which is the legendary proguard.c of the WebFG, just the name is not the same, and then add the following android.mk two sentence: local_proguard_enabled: = fulllocal_proguard_flag_files: = proguard.flags above the full can also be custom, if you do not write this sentence, then you have to add the following sentence: target_build_variant: = user or target_build_variant: = Userdebug so after the execution in the project directory mm can be seen in the Out directory generated shape like Proguard.classes.jar, which means that it has been started in the compilation Proguard but the anti-compilation look, did not appear the network Cloud said ABCD substitution symbol, in fact, the code is not really confused: an The droid turns off the obfuscation option by default at compile time, and has to study build/ The comrade of the core directory will find that there is also a proguard.flags file, in fact, in the process of Proguard, the compiler will call the local directory and the system defined by a number of proguard.flags files, and the confusion in this file option is forbidden, so the compiled apk is still not confused. Therefore, the following sentence is commented out to achieve the real confusion compiled: # Don ' t obfuscate. We only need dead code striping.-dontobfuscate (comment out this sentence with a # #)   Curious comrade can also continue to see why target_build_variant: = user and Local_ Proguard_enabled: = Full Two Select one, see build/core/package.mk: local_proguard_enabled:=$ (Strip $ (local_proguard_ ENABLED) ifndef Local_proguard_enabledifneq ($ (filter user Userdebug, $ (target_build_variant)),) # Turn on Proguard by Default for user & Userdebug buildlocal_proguard_enabled: =fullendifendififeq ($ (local_proguard_enabled), disabled ) # The package explicitly requesT to disable Proguard. local_proguard_enabled: =endifproguard_options_file: =ifneq ($ (local_proguard_enabled), Custom) Ifneq ($ (All_ Resources),) Proguard_options_file: = $ (Package_expected_intermediates_common)/PROGUARD_OPTIONSENDIF # All_ RESOURCESENDIF #!customlocal_proguard_flags: = $ (Addprefix-include, $ (proguard_options_file)) $ (LOCAL_PROGUARD_ FLAGS)  3, how to write Proguard.flags file   parameter interpretation:-include {filename}     read configuration parameters from a given file-basedirectory { DirectoryName}     Specifies the underlying directory for the later relative file name-injars {Class_path}     specifies the application Jar,war to be processed, Ear and directory-outjars {class_path}     Specify the name of the Jar,war,ear and directory to output after processing-libraryjars {classpath}      Specifies the library files required for the application Jar,war,ear and directories to be processed-dontskipnonpubliclibraryclasses     specifies not to ignore non-public library classes. -dontskipnonpubliclibraryclassmembers     Specifies that members of the library class that are visible to the package are not ignored. Retention options-keep {Modifier} {class_specification}     protect the specified class file and members of the class-keepclassmembers {Modifier} {Class_ Specification}     protection of the specified classMembers, if this class is protected they will protect the better-keepclasseswithmembers {class_specification}     protect members of the specified classes and classes, But the condition is that all the specified classes and class members are to be present. -keepnames {class_specification}     protects the names of the members of the specified class and class (if they are not removed in the compression step)-keepclassmembernames {Class_ Specification}     protect the names of the members of the specified class (if they are not removed in the compression step)-keepclasseswithmembernames {class_specification}     protects the name of a member of the specified class and class if all the specified class members are present (after the compression step)-printseeds {filename}     Lists the classes and members of the class-keep option, standard output to the given file compression-dontshrink     does not compress the input class file-printusage {filename}-whyareyoukeeping { Class_specification}     optimize-dontoptimize     do not optimize the input class file-assumenosideeffects {Class_ Specification}     optimizations when assuming a specified method, without any side effects-allowaccessmodification     Optimizations allow access to and modify members of classes and classes with modifiers-dontobfuscate     do not confuse the input class file-printmapping {filename}-applymapping {filename}     Reuse Mappings Add confusion-obfuscationdictionary {filename}     Use the keyword in the given file as the name of the method you want to confuse-overloadaggressively     confusion should beAdd confusion-flattenpackagehierarchy {package_name} by using intrusive overload-useuniqueclassmembernames     to determine the member name of a uniform obfuscation class     repack all renamed packages and place them in a given single package-repackageclass {package_name}     Repackaging all renamed class files in a given single package-dontusemixedcaseclassnames     confusion does not produce a variety of class names-keepattributes {Attribute_ Name,...}     protects a given optional attribute, such as linenumbertable, Localvariabletable, sourcefile, Deprecated, synthetic, Signature, and Innerclasses.-renamesourcefileattribute {string}     sets the string constants given in the source file   4, instance (Skyvideoplayer)-optimizationpasses 3- dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-verbose-dontpreverify-verbose# the Support library Contains references to newer platform versions.# Don ' t warn on those in case this app is linking against an older# plat Form version.  we know about them, and they is safe.-dontwarn-optimizations!code/simplification/arithmetic,!field/*,!class/ merging/* #by jiang#-dontoptimize   #是否对类内部代码进行优化, default optimization # Don ' t obfuscate. We only need dead code striping.#-dontobfuscate   #不进行优化 # items used by third-party jar packages-libraryjars: /libs/fastjson-1.1.23.jar # removes such information by default, so configure it to keep all of it.-keepattributes Si Gnature    #不优化泛型和反射  #android默认项-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 Android.content.broadcastreceiver-keep public class * extends and Roid.content.contentprovider-keep public class * extends Android.app.backup.backupagenthelper-keep public class * Extends Android.preference.preference-keep public class Com.android.vending.licensing.ILicensingService # for Skyworth Fastjson-keep class com.alibaba.fastjson.** {*;}#以下为android默认项-keepclasseswithmembernames 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 *;}  5, Error summary   problem one: When parsing data using the Gson package, the missing type parameter exception program was used to gson the new TypeToken, and the results were packaged into an APK release, and an exception was found, But not by packing the APK when found all normal, baffled its solution, initially suspected did not pack Gson-1.7.1.jar, later after testing found Gson other methods through packaging also can run normally, finally surf the internet for 2 days, finally found the solution in Google Gson Forum. The first type: Add-dontobfuscate-dontoptimize  in proguard.cfg second: Add # removes such information by default in Proguard.cfg so Configure it to keep all of it.-keepattributes signature #Gson specific Classes-keep class Sun.misc.Unsafe {*;} #-keep class com.google.gson.stream.** {*;}  # application classes that'll be a serialized/deserialized over Gson-keep class com.google.gson.examples.android.model.** {*;} Both methods are tested, the first method does not confuse the compilation, the second method can confuse the compilation Problem two: Reflection class can not be confused compile, need to add-keep class com.test.model.response.** {*;} Problem three: Android Helper jar package exception, add-dontwarn Android.support.v4.**-keep class android.support.v4.** {*;} in Proguard.cfg Question four: (same as 1) type conversion error, because I use generics, so when some methods are called, this error occurs, followed by the obfuscation configuration file added a filter generic statement, as follows. After  -keepattributes signature, no similar type conversion errors occur.   problem five: null pointer exception, this error is I compared to the previous error, the time used is relatively short, the beginning is not find out which method is exactly what (because the above mentioned confusion method name is the same), so the class inside all the methods are filtered out, so that I do not use much time, Also found the specific method, but still do not understand the reason, the following found one of the If judgment, I use the reflection screening method, the keyword is "get", suddenly I was shocked, shouted--soga, the original model of the Set/get method name are all confused, so the method is not filtered, A null value is returned, and a null pointer exception is thrown when the return value of the method is used.   WORKAROUND: Filter out all the classes below the model package.   Summary: If you want to use the reflection, the reflection will generally take advantage of the generic type, so you have to filter out the generic, if there is a variable name or method name to judge, remember that the class to be filtered out, also useful to annotation place, to add a line of code, as follows:  - Keepattributes *annotation* so that you can filter out all the Annotation, otherwise you will throw an empty fingerThe needle is abnormal.   Recommended articles, content are they write, I just tidied up a bit, hehe   Original-http://blog.sina.com.cn/s/blog_5f1ebb8f0101lkqz.html http:// blog.csdn.net/hehe9737/article/details/8152330 http://charles-tanchao.diandian.com/post/2012-05-24/ 20118715 http://www.cnitblog.com/zouzheng/archive/2011/01/12/72639.html http://www.eoeandroid.com/ Thread-173733-1-1.html

Android Obfuscation parameter description goto

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.