Correct setup and invocation of Android public libraries in Eclipse (GO)

Source: Internet
Author: User

Transfer from http://www.cnblogs.com/SkyD/archive/2011/09/01/2161502.html Introduction

has been a headache before there is no way to share resources in more than one program, the method used as a public class library is also used to export the jar re-import methods, and now finally initially understand, can be calculated free ~, share out.

Building a public Library

First build the public library of the Android project, named Mycorelib:

When finished, right-click on our new project in the left package browser and select Properties:

Select Android category on the left and the IS library option on the right:

When you are finished, delete the default generated resource in Package Explorer to avoid a conflict when it is referenced later:

Open Androidmanifest.xml, delete the red part of the code:

Add a test resource

Now that the initial empty library is complete, let's add a resource for other programs to use, and here I just add a string resource named Libname:

Build test projects and introduce public libraries

Now create a new project named Libtest to try calling the public library:

or right-click on an item and select Properties:

Or left select Android category, right click on the Add button to select to add the Mycorelib class library to the project:

When you are finished, add to the project:

You can also see the Mycorelib package name and its resource ID under the Gen directory:

But at this point you will find that the string resource is inexplicably two previously deleted resources, this is actually because the referenced resources and the program's default package of resources together, you can see the default package above the resource ID and here is also the same.

In other words, you can invoke resources directly from a reference in a way that uses local resources.

To test the resources that call the common library

For example, in Androidmanifest.xml, such modifications:

In the Java code is also used to call the default resources directly call, of course, you can also display the package name to join the public library to call, but the inclusion of the method to display the package name does not work in the XML file, multiple attempts are prompted to find a resource, That is, the public library resource can only be called in XML in a way that invokes the default package resource.

Compile and run the effect:

You can see that the contents of the resources we set up in the public library are displayed correctly.

Conclusion

This method of invocation is not just making the resource call possible, and the public code is much more convenient to edit than the Jar method.

Before looking for this method on the Internet for a long time have not learned, at this point suddenly think of reference scoreloop method, finally to understand it.

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.