Android code confusing part of the class without confusing tricks

Source: Internet
Author: User

After writing the Android program, we usually want to encode code, so as to ensure that our application in the market will not be anti-compilation, and then crack, so we need to release the official version of the time, there are some kinds of things can not be confused, such as the implementation of Serializable interface, otherwise the deserialization error occurs, in which case we can simply add a configuration to the Proguard.cfg (Eclipse) to resolve:

<  Fields > ;p rivate void WriteObject (java.io.ObjectOutputStream);p rivate void ReadObject (Java.io.ObjectInputStream); Java.lang.Object writereplace (); Java.lang.Object readresolve ();}
The above configuration indicates that all classes that implement the Serializable interface and their members are not confused. Again such as JS calls the Android Javascriptinterface code method, such as individual control layer class need to reflect, individual entity class need JSON to save local, these are to prevent no obvious common characteristics of the class is confused, this time, how do we do it, Add it to proguard.cfg? This causes the Proguard configuration file to be cluttered and requires all members of the team to have an understanding of their syntax. Here's a little trick to share, by adding a common identity to these classes, properties, functions, and then unifying the filtering, finally solving the problem described above, solution 1. Create a new annotation that represents a unified identity Notproguard
 Packagecn.trinea.android.common.annotation;ImportJava.lang.annotation.ElementType;Importjava.lang.annotation.Retention;ImportJava.lang.annotation.RetentionPolicy;ImportJava.lang.annotation.Target;/*** Notproguard, Means not proguard something, like class, method, field<br/>**@author<a href= "http://www.trinea.cn"target=" _blank ">Trinea</a> 2015-08-07*/@Retention (Retentionpolicy.class) @Target ({elementtype.type, Elementtype.method, Elementtype.constructor, Elementtype.field}) Public@InterfaceNotproguard {}
Notproguard is a compile-time annotation and does not have any impact on run-time performance. You can modify a class, method, constructor, property. More knowledge about annotations is visible: Java Annotation Introduction and several common open source project annotation principle Analysis 2. Filter elements that are modified by this annotation in the Proguard configuration file
<  Fields >  <methods>;}
Indicates that classes, properties, and methods that are notproguard decorated are not confused. 3. Use (1) the whole class is not confused
 Public class User {}
(2) Single attribute is not confused
 Public int ID;
(3) Single method does not confuse
@NotProguard  Public Boolean isValid () {...}
This solves the problem that each class needs to be configured in the Proguard configuration file. Thirdly, confusion and confusion generally in the Release mode effective, there are three functions: (1) compression, optimization, deletion of code, (2) to a certain extent, improve the difficulty of reading after the anti-compilation, (3) by removing the function of the code to achieve the special role. For example, in the Proguard syntax and common PROGUARD.CFG code introduced in the use of Progurad so that the online version does not print LOG.D and log.v skills, to prevent debugging sensitive information is leaked. Some of the application code may never be confused, although the actual value of the code may not be small, itself may also be open source code together, and the cracked still can be cracked, but the spirit of doing things to professional attitude, or confused it. About Proguard Basic can be consulted: Proguard grammar and common proguard.cfg code Proguard function, use and BUG analysis

Some of the confusing parts of the Android code are not confusing tricks

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.