How does one Package Multiple android projects into an apk? The principle is that a main project references other projects, and other projects are referenced like jar packages, of course, it is quite different from the jar reference principle. The following is a detailed description. Most of them are translated articles on the official website development wizard. 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
All the components in the library project used in the current program must be added to the file.
. 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 the manifest file, see the documentation for AndroidManifest. xml.