1

I'm using Android Studio 1.2.2 and just downloaded 1.3RC3, as it reputedly has full NDK support.

I have a working project while my .c / .h files remain in app/src/main/jni; however, I want them in AndroidProject/../common/src, i.e. outside the android project folder. How do I make this work?

To reiterate: this question is about EXTERNAL, NATIVE CODE; not importing external java!

Engineer
  • 7,543
  • 7
  • 57
  • 96
  • Looking at the accepted answer for http://stackoverflow.com/questions/21096819/jni-and-gradle-in-android-studio, it seems like you could use that approach to specify where your native sources are located (I haven't tried this myself, as I'm still using Eclipse). – Michael Jul 22 '15 at 20:07

1 Answers1

2

This was so simple, I didn't think to even try it at first, but it worked at once:

android{
   ...
   sourceSets.main.jni.srcDirs = ['../../common/test']
   ...
}

...which implies that the path is relative to AndroidProject/app.

A problem with this solution is that it is incompatible with a standalone Android.mk, since preventing Android.mk generation by gradle requires sourceSets.main.jni.srcDirs = [].

Engineer
  • 7,543
  • 7
  • 57
  • 96
  • Consider updating your answer to link to [Experimental Plugin User Guide](http://tools.android.com/tech-docs/new-build-system/gradle-experimental), that way it has less change to get outdated as they update the DSL. – proppy Aug 03 '15 at 07:16