How to deal with constants in Android code obfuscation

Source: Internet
Author: User

Recently has been studying code obfuscation, which found that some of the common constants we define after the code confusion, after the anti-compilation, even after the full display in front of my eyes, such as the service request address, unexpectedly in the form of a full path is displayed in the confusion of the code, more than their definition of the complete, if so , does it make sense to confuse code? At that time very depressed, but another thought, constants must not be confused, if the constant is confused, 1 hybrid 2, other places to quote will inevitably error ah, then how to do? Want to confuse, and don't want to make the more important constant blatant display? There must be some way, but you may not want to think. We can compare the original project with the extracted project structure after the confusion, you know what to do:

See the difference, right, the difference is in the values folder, so what can you think of? We can define the relevant constants in the String.xml resource file under the Values folder, which can be referenced in the code with GetString (R.STRING.XXX), so that there is no more constant content in the plaintext form in the post-compilation code.

There may be some children's shoes do not understand exactly what to do, now bloggers say the approximate method:

We typically define a common class in the project, such as: Const.java, which contains a number of frequently used constants (including service addresses) such as:

[HTML]View Plaincopy
    1. public static final String server_ip = "192.168.0.1";

This kind of writing, after the anti-compilation is very easy to see, according to my method, it should be this:

[HTML]View Plaincopy
    1. public static String server_ip = "";

Then define a value for SERVER_IP in String.xml:

[HTML]View Plaincopy
    1. <string name="server_ip">192.168.8.2</string>

The constant CONST.SERVER_IP is then assigned in the OnCreate method of the application in its own project:

[HTML]View Plaincopy
    1. const.server_ip=getString (R.STRING.SERVER_IP);

How to deal with constants in Android 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.