How to modify the package name of a jar file under Android programming

Source: Internet
Author: User
Tags throw exception

First of all we have to say why to modify the jar file package name, jar package we will be very high frequency use, especially with some other three-party library, often the Java code into a jar file, easy to use the project dependencies. The author encountered some problems in the development process, because the jar file inside the package name and the project or runtime Environment reference file package name conflict caused, this time we modify the jar file package name is a relatively fast and effective solution. Give two examples, the author personally experienced two situations.

    • Gson Library: This is believed to be used by a lot of people, but directly into the Gson jar package, the HTC Desire HD This phone will throw an exception (typenotfoundexception)
    • Jackson Library: This is also a JSON parsing, we are doing apple push back-end, the background with Java write, use Java-apns library, rely on Jackson, and then run will throw exception, the specific reason is not checked, the initial suspicion of the package name conflict, modified after the solution.

Here's how to modify the package name of a jar file, which requires a gadget called Jarjar.jar

    • : http://code.google.com/p/jarjar/downloads/list

Here we take Gson.jar as an example, in the Gson.jar package directory to create a new text file, the name is arbitrary, such as Rule.txt, write the following content.

Rule com.google.gson.** [email protected]

It is written to modify the rules, and we will modify the Gson in the package name to Mygson. Open the command line and enter the following command.

Java-jar Jarjar.jar process Rule.txt Gson.jar Mygson.jar

command execution, the same directory will be more Mygson.jar, this is the change package name after the jar file, our project import this jar package to use.

How to modify the package name of a jar file under Android programming

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.