Unable to get additional Java source directories to work with Gradle Experimental plugin

82 views
Skip to first unread message

Pol

unread,
Jun 6, 2016, 3:42:52 PM6/6/16
to android-ndk
Hi,

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 {
            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 "../../JavaBindings/java" and now ignores what's in "src/java".

However for the "app/jni" directory in the UI, it works: both what's in "src/jni" and "../../JavaBindings/jni" shows up.

- Pol

Raymond Chiu

unread,
Jun 7, 2016, 2:33:56 PM6/7/16
to android-ndk
Hi Pol,

Could you file a bug as b.android.com?  Thanks.

Raymond

Pol

unread,
Jun 12, 2016, 12:50:03 AM6/12/16
to android-ndk
Hi Raymond,

For the record, 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"   <------- REQUIRED SINCE DEFAULT IS NOT PRESERVED
            srcDirs += "../../JavaBindings/java"
        }
        jni.source {
            srcDirs += "../../JavaBindings/jni"
        }
    }
}

- Pol

Raymond Chiu

unread,
Jun 20, 2016, 8:50:09 PM6/20/16
to android-ndk
I filed https://code.google.com/p/android/issues/detail?id=213173 to keep track.  Thanks for the detailed information!
Reply all
Reply to author
Forward
0 new messages