Android package a jar package containing activity and resource files and call it in the project

Source: Internet
Author: User
Studying how to package resources and activity files into jar files for project calls has taken a lot of detours and tried different methods, which is not ideal, finally, we found the perfect solution from the official Android documentation. Here is a summary.

I recently released a small application "Poetry Daquan". If you are interested, please provide your valuable comments. Thank you.

This blog post is a summary of the translation of Android development documents and the specific situation of individuals in the development process.
Step 1: set a common android project as a library project

The Library Project is also a standard Android project, so you should first create a common android project. This project can start with any name, registration, and other fields to be set, as shown in 1.

Set the project as a database project. The procedure is as follows:

  1. InPackage Explorer, Right-click the project folder, and clickProperties.
  2. InProperties window, Select "android ",LibraryProperty is displayed on the lower right side.
  3. Select "is library" single region, and then clickApply.
  4. ClickOKClosePropertiesWindow.

In this case, the project becomes a library project.

Of course, the Java project can also be converted into a library project, which is very simple. Execute the above four steps. Other Program projects can reference the library project.

Figure 1. Make a project a library project

Create a manifest File

The manifest file of a library project is the same as that of a standard Android Application, declaring all shared components.

For example, in the example of tictactoelib in apidemo, the Library Project declares the activityGameActivity:

<manifest>  ...  <application>    ...    <activity android:name="GameActivity" />    ...  </application></manifest>
Step 2 reference the Library Project

If the application you develop wants to include the code and resources in the library project, the reference steps are as follows:

  1. InPackage Explorer, Right-click the project folder, and clickProperties.
  2. InProperties window, Select "android ",LibraryProperty is displayed on the lower right side.
  3. ClickAdd, OpenedProject selectionDialog box.
  4. Select a project from the list of available library projects, and then clickOK.
  5. Close the dialog box and clickApply(InPropertiesWindow ).
  6. ClickOKClosePropertiesWindow.

After completing the above six steps, eclipse will recreate the project and include the content in the library project. 2.

Figure 2.Let the project reference a library project

If you want to add references to multiple library projects, you can use up and down to set their relative priority and merge order. When the tool merges referenced databases, the order is from low-priority (below the List) to high-priority (above the list ). If more than one database defines the same resource ID, this tool selects a resource with a higher priority. The application itself has the highest priority, and its resources zthe application itself has highest priority and its resources are always used in preference to identical resource IDs defined in libraries.

 

Declare the components in the library in the menifest File

In the manifest file, you must add all the components in the library project used in the current program. For example, you must declare any <activity>, <service>, <extends ER>, <provider>, <permission>, <uses-library>, similar to other elements.

When declaring components in a library project, you must use the full name of the class containing the package name.

In the tictactoemain example, declare the library Activity gameactivity:

<manifest>  ...  <application>    ...    <activity android:name="com.example.android.tictactoe.library.GameActivity" />    ...  </application></manifest>

For more information about androidmanifest, see androidmanifest. xml.

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.