Using Android Studio 2.1.1 with Experimental Grade plugin 0.7.2, I'm trying to add another Java source code directory to the module. Here's the relevant section from the module Gradle settings:
android.sources {
main {
java.source {
//srcDir "src/java"
//srcDir "../../JavaBindings/java"
//srcDirs += "src"
srcDirs += "../../JavaBindings/java" <--- DOES NOT WORK
}
jni.source {
srcDirs += "../../JavaBindings/jni" <--- THIS WORKS
}
}
}
After looking around on Google and Stack Overflow, I tried a number of different syntaxes, but no luck. The app/java
directory in the Android Studio project structure UI only shows what's in src/java
and does not include what's in ../../JavaBindings/java
.
However for the app/jni
directory, it works: both what's in src/jni
and ../../JavaBindings/jni
shows up.
After looking at the source code for the Gradle Experimental plug-in, I eventually figured it out:
java.source.srcDirs
and jni.source.srcDirs
do not behave the same: for the JNI case, even if you define the jni.source.srcDirs
setting, src/main/jni
is always included by default, but that's not the case for the Java case.
So the correct syntax becomes:
android.sources {
main {
java.source {
srcDirs += "src/main/java"
srcDirs += "../../JavaBindings/java"
}
jni.source {
srcDirs += "../../JavaBindings/jni"
}
}
}