Add a local library project as a dependency on multiple projects in Android Studio

I created a library project in Android Studio (currently 0.5.2) by choosing File > New Project... > "Mark this project as a library" .

enter image description here

I have two other non-library projects that I would like to add to this library project.

 -My Library -Project 1 (depends on My Library) -Project 2 (depends on My Library) 

My goal is to maintain the independence of each project and avoid duplication of modules / code. How can this be done without copying the library module into other projects?

Update: Android Studio 0.6.0 allows you to import a module, but it just copies the module source to the project.

+8
android-studio dependencies
source share
3 answers

You can also access the library outside of your project folder using the project () property. projectDir. If your external library is similar to your project

 - MyLibrary - library - MyProject - app 

in MyProject / settings.gradle

 include ':library' project(':library').projectDir = new File(settingsDir, '../MyLibrary/library') 

in MyProject / app / build.gradle

 dependencies { compile project(':library') } 
+21
source share

This is very similar to this question:

Sharing Android library between multiple Android apps using Gradle

Instead of clicking on the central part of maven, you can click on your local maven repository (mavenLocal () in build.gradle)

+1
source share

Another route (if you do not want to deploy the library somewhere) is to use VCS and check the library as part of your project. Git has submodules for this, Mercurial has subrepos, and SVN has an appearance to name a few. Then add it to your Gradle construct using the project dependency.

0
source share

All Articles