IntelliJ IDEA supports Android library projects
that hold shared Android source code and resources.
Other Android application projects can reference a library project and include its compiled sources in their .apk files at build time.
In IntelliJ IDEA, library projects are supported through separate library modules.
To enable sharing Android source code and resources, do one of the following:
- Create a new Library module.
- Convert an Application module that contains sources you want to share into a Library module.
In this topic:
- Creating a Library module
- Converting an Application module into a Library module
- Using a Library module in another project
- Adding data from AndroidManifest.xml for a library module to AndroidManifest.xml for the entire application
- Including the .dex file of a library module into the .apk of the entire application without rebuilding (pre-dexing)
- Do one of the following:
- On the first page of the wizard, select Android in the left pane and Library Module in the right pane.
- Complete the wizard.
- Open the Project Structure dialog box by choosing from the main menu.
- Select Modules in the left pane. In the central pane, expand the node of the module that you want to turn into a Library module and click Android.
- In the right-hand pane, select the Library module checkbox on top of the Android facet page.
- From the main menu, select File | New | Module from Existing Sources.
-
In the dialog that opens, browse to the
.imlmodule file that you want to import and click OK. The module node will be added to the tree view. -
Add dependencies on the imported library module to the modules where its data is going to be used:
- Open the settings of the non-library module: navigate to File | Project Structure, select Modules in the left pane and select your non-library module in the central pane.
-
In the right pane, switch to the Dependencies tab. Click the Add button
in the toolbar on the right
and select Module Dependency from the context menu.
- In the Choose Modules dialog box that opens, select the imported library module from the list and click OK.
Adding data from AndroidManifest.xml for a library module to AndroidManifest.xml for the entire application
- Open the Project Structure dialog box by choosing from the main menu.
- Select Modules in the left pane. In the central pane, expand the non-library module and click the Android facet under its node.
- In the right pane, on the Android facet page, switch to the Packaging tab and select the Enable manigest merging option.
Including the .dex file of a library module into the .apk of the entire application without rebuilding (pre-dexing)
- Open the Project Structure dialog box by choosing from the main menu.
- Select Modules in the left pane. In the central pane, expand the non-library module and click the Android facet under its node.
- In the right pane, on the Android facet page, switch to the Packaging tab and select the Pre-dex external jars and Android library dependencies option.