How to Package Multiple android projects into one apk (how to reference other projects in your project)

Source: Internet
Author: User
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:

  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
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.

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.