Creating a Library module

On the first page of the wizard, select Android in the left pane and
Library Module in the right pane.

Complete the wizard.

Converting an Application module into a Library module

You can convert an Application module into a Library module by updating its Android facet.

Open the Project Structure dialog box by choosing
File | Project Structure 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 check box on top of the Android facet page.

Using a Library module in another project

To use a Library module in another project, you need to import this module into it.

From the main menu, select File | New | Module from Existing Sources.

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.

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

To successfully integrate a library module into another application, its components must be declared in the application AndroidManifest.xml file.
The manifest file contains the information that is required to run the application (for more information, see App Manifest).
You can either add this information on a library module manually, or extract it from AndroidManifest.xml of the library module
and add it to the AndroidManifest.xml of the application automatically.

The second approach is referred to as merging manifests.

To have the manifest of a library module merged with the application manifest automatically:

Open the Project Structure dialog box by choosing
File | Project Structure 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)

During the application packaging, the .class files of a library module are converted into .dex files. This operation is referred to as dexing.
Finally, the .dex files output from the library module is included in the final application .apk (learn more about the building procedure from
Building and Running).

As a rule, the contents of a library module remain unchanged. In this case you can have them dexed only once,
whereupon the output .dex files are included in the .apk. This approach is referred to as pre-dexing.

By default, IntelliJ IDEA pre-dexes library mode dependencies as well as external jars that have not been updated since the previous build. You can change these settings
so that all .class files are always dexed.

Open the Project Structure dialog box by choosing
File | Project Structure 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.