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:
- InPackage Explorer, Right-click the project folder, and clickProperties.
- InProperties window, Select "android ",LibraryProperty is displayed on the lower right side.
- Select "is library" single region, and then clickApply.
- 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:
- InPackage Explorer, Right-click the project folder, and clickProperties.
- InProperties window, Select "android ",LibraryProperty is displayed on the lower right side.
- ClickAdd, OpenedProject selectionDialog box.
- Select a project from the list of available library projects, and then clickOK.
- Close the dialog box and clickApply(InPropertiesWindow ).
- 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.