Use JAR-CVF *.jar * and direct islibrary to generate a jar package comparison (package and invocation of JAR packages in Android)

Source: Internet
Author: User

Comparison of jar packages generated using JAR-CVF *.jar * and direct islibrary

JAR-CVF *.jar * will pack resources i.e. R.java, Buildconfing.java and Mainactivity.java

The IS library will only mainactivity.java the package

Baidu: (but still do not think to solve my doubts)

In the Android development process, we often have this requirement, we develop a class library jar package, provided to others to call. The problem arises when project A is encapsulated as a jar package for Project B, and the activity of Project A is invoked in Project B: resource file not Found (exception: Error/androidruntime (3341): caused by: Android.content.res.resources$notfoundexception:stringresource ID #0x7f060007). The problem is that only the code under the SRC folder can be shared, not the RES resource file, enough to be depressed! Create a androidproject, with the export of Eclipse, remove androidmanifest.xml,res, so that only the code is shared, and the RES resource file called in this code is not working properly, otherwise it throws Res. Resources$notfoundexception exception. So how to solve it?

1. If you are using only shared code, and the shared code does not involve a call to the RES resource file, export the jar package directly in Eclipse and reference it in the desired project.

2. If the code is shared and the shared code involves a call to the RES resource file, the Web-based method is to place the RES resource file in the Assets folder, load the processing in the SRC code, and then export the jar package with Eclipse, and the reference ( The res resource can be hit into the jar package, but when other projects call the jar package, the reference ID in the jar package points to the resource of the current project, about how to make the resource reference in the jar package just want the res file in the jar package to be temporarily free of solutions. My problem solved, solution: Put the picture resources into the assets package and into the jar package, layout can only use code.  The code in the jar package can successfully refer to the assets file within the jar package. Another: The JNI layer cannot be packaged into a jar package and can only be supplied to a third party with the jar package and placed in the Libs package in the project directory.

3. If you share code and involve a call to the RES resource file, and you do not want to place the RES resource file in the Assets folder, the problem arises when you generate the jar package directly:

1). When referencing this jar package in another project, a small red fork appears in the project name, and the product manager must learn the five tricks of the product approach product Design Interactive experience Console console directly automatically prompts: Errorgenerating Final archive: Found duplicate file for apk:res/drawable-hdpi/icon.png, the usual workaround is to remove the prompt's resource files in this project that can be compiled, and then generate the jar package.

2). Delete the public icon and other resource files, generate jar package, at this time in the project reference, console console no automatic error phenomenon. If the activity in the jar package invokes a file in the Res resource folder, the problem arises when the acticity in the jar package is called in the current project, and the RES resource referenced by the activity throws an exception if the value in the Strings.xml file is referenced Error/androidruntime (3341):caused  by:  Android.content.res.resources$notfoundexception:stringresource id#0x7f060007. If you refer to a file in the Layout folder, you can find the XML in layout, such as ee.xml in Layout, you can find r.layout.ee, but the control ID defined in Ee.xml is not referenced and throws an exception error/ Androidruntime (13703): caused by:java.lang.NullPointerException. If a call in the current project that does not involve the RES in the jar package is called, everything OK.                  

4. If the code is shared and the calls to the RES resource file are involved in the shared code, if encapsulated into a jar package, this method is not required (call the activity encapsulated in the jar, but also ensure that the activity in the jar package calls the RES resource encapsulated in the jar, which says , the RES resource portion of the jar package is called empty), so how can you meet the requirements?  To do the project to generate the jar package, select the Islibaray of the Android tab in the Properties window of the Jar package project, click the Apply button or the OK button (at this point, the JAR package item then right-click to select runas→ The androidapplication will be able to run normally). In the project to refer to the jar package, right-click the project name, open the Properties box, select the Add button on the right side of the Islibaray tab of Android to add the Jar package project. This allows the activity in the JAR project to reference the RES resource in the JAR package project normally. Project invoke jar Package project activity is normal.

Use JAR-CVF *.jar * and direct islibrary to generate a jar package comparison (package and invocation of JAR packages in Android)

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.