IntelliJ IDEA 14.0.0 Web Help

Sharing Android Source Code and Resources Using Library Projects

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

  1. Do one of the following:
  2. On the first page of the wizard, select Android in the left pane and Library Module in the right pane.
  3. Complete the wizard.

Converting an Application module into a Library module

  1. Open the Project Structure dialog box by choosing File | Project Structure from the main menu.
  2. 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.
  3. In the right-hand pane, select the Library module check box on top of the Android facet page.

Using a Library module in another project

  1. From the main menu, select File | Import Module.
  2. In the dialog that opens, browse to the .iml module file that you want to import and click OK. The module node will be added to the tree view.
  3. Add dependencies on the imported library module to the modules where its data is going to be used:
    1. 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.
    2. In the right pane, switch to the Dependencies tab. Click the Add button add.png in the toolbar on the right and select Module Dependency from the context menu.
    3. 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

  1. Open the Project Structure dialog box by choosing File | Project Structure from the main menu.
  2. Select Modules in the left pane. In the central pane, expand the non-library module and click the Android facet under its node.
  3. 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)

  1. Open the Project Structure dialog box by choosing File | Project Structure from the main menu.
  2. Select Modules in the left pane. In the central pane, expand the non-library module and click the Android facet under its node.
  3. 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.

See Also

Last modified: 4 December 2014
comments powered by Disqus