Creating a standalone library module in android studio

Building a stand-alone library application is a common task in Eclipse + ADT. I thought it should be a simple task in Android Studio (1.2 or higher), but after running into this issue for two days, I realized that Google hadn't done anything about it and the implementation of the standalone The library module is not as simple as I thought, so I decided to share my experience with you.

+3


source to share


1 answer


To create a standalone and reusable library module in Android Studio:

1- Create a new project with no activity.

2- The new default module for the project is called app

. Right click on the module and refactor / rename it to something like "library". Close Android Studio.

3- Open file explorer and rename the module folder from app

to library

.

4- Open the folder .idea

. There are some XML files in there that have folder links app

. Replace app

with library

in these files.

5- Open the module gradle file (library / build.gradle) and change the plugin to com.android.library

. Then delete applicationId

.

6- Open Android Studio. Rebuild the module. If there are no mistakes, we do it here.

7- Open the application that depends on this module. Open settings.gradle

and enable the module library

as shown below:



include ':library'
project(':library').projectDir = new File('/Path/To/LibraryProject/library')

      

8- Open the app

module app build.gradle

and add this line to the section dependencies

:

compile project(':library')

      

9- Rebuild your project. If everything goes right, you will see the module library

in your project. You can edit a module library

from there and / or its project and more importantly: you now have a standalone library module that can be reused across multiple projects!

Hopefully Google will make this process a lot easier in future versions of Android Studio!

EDIT:

I checked Android Studio version 1.4 and hopefully in this version we can omit steps 3 and 4.

+10


source







All Articles