Android studio add external project to build.gradle Android studio add external project to build.gradle android android

Android studio add external project to build.gradle


Assuming that Some Other Folder is a gradle project you could add something like the following to your settings.gradle file:

include ':module1'project(':module1').projectDir = new File(settingsDir, '../Project B/Module 1')


You have to put in your file settings.gradle this lines:

include ':module2'project(':module2').projectDir = new File(settingsDir, '../Project 2/Module2')

Then you have to add in your builde.gradle (Module: app) in the dependencies tree, this line:

implementation project(':module2')

or go into the Project Structure > app > Dependencies, click on Add, choose 3 Module Dependencies and select your module


With Gradle 1.10 (don't know what other versions this will be valid for) this is what I came up with based on a response given here http://forums.gradle.org/gradle/topics/reference_external_project_as_dependancy

I have an api library project, a common library project and the main app project. Each is a stand-alone development project and the two libraries are meant to be shared between multiple apps.

In settings.gradle for the common project:

def apiLibDir = file('../android-api/android-api-lib')def rootProjectDescriptor = settings.rootProjectsettings.createProjectDescriptor(rootProjectDescriptor, 'android-api-lib', apiLibDir)include ':android-api-lib'

Then in the main app project settings.gradle:

def apiLibDir = file('../android-libs/android-api/android-api-lib')def rootProjectDescriptor = settings.rootProjectsettings.createProjectDescriptor(rootProjectDescriptor, 'android-api-lib', apiLibDir)include ':android-api-lib'def commonLibDir = file('../android-libs/android-common/android-common-lib')settings.createProjectDescriptor(rootProjectDescriptor, 'android-common-lib', commonLibDir)include ':android-common-lib'

In each of the respective build.gradle files you just reference them by the name you gave them in the settings.createProjectDescriptor like you would any other project dependancy:

dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    compile project(':android-api-lib')    compile project(':android-common-lib')}

This seems to work. It didn't even throw an error for multiple DEX files defining the api library, I suspect because it was all part of the same build process and Gradle was smart enough to figure it all out.