Correctly establishing and calling the android Public Library in eclipse

Source: Internet
Author: User
Introduction

It has been a headache before, but there is no wayProgramShared resources, the method used as a public class library is also the method used to export jar and re-import. Now I have understood it at first, but it is quite free ~, Share it.

 

Create a public database

First, create an android project named mycorelib for the Public Library:

Right-click the new project in the left-side package browser and select properties:

Select Android category on the left and is library on the right:

Delete the default Resources in the package Resource Manager to avoid future reference conflicts:

Open androidmanifest. xml and delete the red part.Code:

 

Add test Resource

Now the initial empty library has been created. Now we can add a resource for other programs. Here we only add a string resource named libname:

 

Create a test project and introduce Public Libraries

Create a project named libtest to call the Public Library:

Right-click a project and select properties:

Select Android category on the left, and click Add on the right to add the mycorelib class library to the project:

After the configuration is completed, it is added to the project:

The package name and resource ID of mycorelib are also displayed in the gen directory:

However, at this time, you will find that there are two more resources that have been deleted in the string resource. This is because the referenced resources have been mixed with the resources in the default package of the program, you can see that the resource ID in the default package above is the same as that in the following.

In other words, you can directly call referenced resources by using local resources.

 

Test the resources of the public library called

For example, in androidmanifest. XML, modify the settings as follows:

In Java code, you can also directly call the default resource by calling it. Of course, you can also display the package name added to the public library for calling; however, the method for adding the display package name does not work in the XML file. If you try multiple times, you are prompted that the resource cannot be found. That is to say, in XML, you can only call the default package resources to call the public library resources.

Compilation and running results:

We can see that the resource content we set in the public database is correctly displayed.

 

Conclusion

This call method not only makes resource calls possible, but also makes public code easier to edit than jar, which is very practical.

I have never been informed of this method on the Internet for a long time. Now I suddenly think of the reference method of scoreloop, and I finally figured it out.

Related Article

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.