Android Library project jar packaging and obfuscation

Source: Internet
Author: User

The company has a project to be provided to the third party in the form of libraries, but Java code does not want others to know, there are also resource files need to be packaged together, very common needs, the following is the process of resolving this matter.

1, directly to the library project to the third party, the Android Library project reference method

By the boss Pass, code customers can see, No.

2, the Library project Testlib SRC exported to a jar, the Res directory directly to third parties

Failed. The exported jar is still referenced to the library project's R file (COM.TEST.LIB.R), but after the resource is provided to a third party, the generated R is COM.TEST.R, so the runtime cannot find the COM.TEST.LIB.R, citing the resource error.

3, a new library project Mylib, The package name is the same as the Testlib project (com.test.lib), then delete the Mylib res, copy all Testlib res to the new project, and copy Testlib from Testlib.jar to Mylib folder, and then the third party references M Ylib, Success!

In the middle of the episode, we did not use the jar generated below the bin, two is similar to the second part of the direct import jar file, the other and step three the same, but the runtime still error--know friends want to tell me why.

4, step three solves the Java source code does not directly provide to the third party problem, but if with the jar viewer, still can see the source code, namely step three generated jar is no confusion, then we will confuse jar.


Jar Confusion believe Step

4.1 Locate the confusing run file directory (*\android-sdk-windows\tools\proguard\bin) below the SDK to open the Proguardgui.bat;


4.2 The following screen appears, click the Load button, load the *\android-sdk-windows\tools\proguard\proguard-android-optimize.txt file, click Next.

4.3 The following screen appears, click on the Red box three buttons, respectively select the jar to encrypt, encrypt the output jar, and the project reference to the Jar (Android.jar). Click Next.


4.4 In the Red box tick, click Next;

4. 51 Click Next until the following screen appears, click Process:

4.6 , will appear as on the log, you can see and r related to the error, find R related content, because R is not in the jar, then we can ignore between (Dontwarn), because we want to provide mylib to third parties, can get r related content, This is the reason why the second method is not effective. For example, we open the Proguard-android-optimize.txt, Tianjin red box inside the 2 words, ignoring r related content.


4.7 Repeat step 2~6 again, which appears:


4.8 Find our output directory, we can see the corresponding *after file, we open with the jar viewer to see, let the boss rest assured, let the code Nong disgusting confusion after the codes out, mom no longer have to worry about the third party know our business processes and interfaces:



4.9 At this point, the task is complete. [Email protected] Welcome to the exchange.


Resources:

1. Android Code jar package Library Project integration
2. How to confuse the Android jar package

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Library project jar packaging and 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.