Reputation: 6403
I have some java classes that sits in it's own directory outside the main project (but in the same project folder).
The folder setup looks like this:
root
|
|
|- Main project
|
|- Dir
| |-src
| |-libs
|
|- more android libs...
I want to include the Dir/src classes in the Main Project.
I've tried this in the Gradle build files:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', ':Dir/src']
...
To no avail.
Is there a solution to this?
Upvotes: 1
Views: 5154
Reputation: 6403
I'm building on Dodge's answer and actually post the Gradle code that fixed this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'java'
sourceCompatibility = '1.6'
targetCompatibility = '1.6'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
sourceSets {
main {
java {
srcDirs = ['src']
}
}
}
buildDir = 'bin'
Upvotes: 2
Reputation: 8297
you might want to make your Dir
a own module
add include 'Dir'
to your settings.gradle
create a build.gradle inside your Dir
directory with this content apply plugin: java
now you can go into your main projects build.gradle
and add to dependencies: compile project(':Dir')
if your Dir
uses android related stuff, you might want to use the New > Module
(right click on your project in Android Studio) Function of Android Studio to create an Android Library.
But i haven't tested that feature yet. If Android Studio throws an Exception when trying to use the New Module, you should try to update Android Studio, in the latest Version it works for me.
You might also want to check the Gradle User Guide and the DSL Reference both are very helpfull in getting into Gradle and understanding it.
Upvotes: 4