Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require Gradle project from another directory

I have a directory/project setup like this:

C:\     _dev\         Projects\             Logger             MyProject 

Logger is an Android library project using Gradle. MyProject is a standard Android project project that needs to make use of the Logger library.

I am using Android Studio and have tried adding Logger to the external libraries. Whilst this works during development, I get messages about the class not being found when building.

I'm completely new to Gradle, but have tried the following in my build.gradle within MyProject:

buildscript {     repositories {         mavenCentral()     }     dependencies {         classpath 'com.android.tools.build:gradle:0.5.+'     } } apply plugin: 'android'  repositories {     mavenCentral() }  android {     compileSdkVersion 18     buildToolsVersion "18.1.0"      defaultConfig {         minSdkVersion 16         targetSdkVersion 18     }      dependencies {         compile files("../Logger")     } }  dependencies {     compile 'com.android.support:gridlayout-v7:18.0.0'     compile 'com.android.support:appcompat-v7:18.0.0' } 
like image 541
Euan T Avatar asked Oct 10 '13 14:10

Euan T


People also ask

How do I change directory in gradle?

On android studio just go to File > Settings > Build Execution, Deployment > Gradle > Service directory path choose directory what you want.

How do I add a project to gradle?

To include another gradle project you need to edit the settings. gradle file of the current project. In the current project's settings. gradle file, you have to add the project's name which you want to include in the current project.

How do I move a .gradle folder to my D drive?

gradle folder to the new location. Move by either by dragging and dropping while holding the Shift key, or using the File Explorer context menu (normally right-click) and selecting cut, and then paste to the new location.


1 Answers

The simplest way is to make MyProject a multi project with the Logger project as a subproject.

settings.gradle in MyProject directory:

include ":logger" project(":logger").projectDir = file("../logger") 

In the build.gradle of MyProject you can now reference this lib as a project:

dependencies {      compile 'com.android.support:gridlayout-v7:18.0.0'      compile 'com.android.support:appcompat-v7:18.0.0'      compile project(":logger") } 
like image 154
Rene Groeschke Avatar answered Sep 18 '22 23:09

Rene Groeschke