How to set up JNI sources structure in Android Studio


(Xing) #1

(I’ve already post this question in StackOverflow but got no help till now, so I come, copy and past it here.)

Let’s say we got codes with structure as bellow

src/
├── androidTest
├── app.iml
├── build.gradle
├── main
│   ├── AndroidManifest.xml
│   ├── java
│   ├── jni
│   │   ├── common
│   │   │   ├── inc
│   │   │   │   ├── common.h
│   │   │   │   ├── ...
│   │   │   └── src
│   │   │       ├── common.cc
│   │   │       ├── ...
│   │   └── native-media.cc
│   └── res
├── proguard-rules.pro
└── test

I want to tell Gradle all the sources in main/jni should be compiled. If I just leave it, AS(Android Studio) will use all the files in jni directory to compile. But if there’s some sub directories, like common/inc and common/src here, AS will get confused.

I googled a lot, but all the ways I found does not work.(e.g. Gradle-experimental, actually Android Studio will complain and strike if I follow that.)

So, what’s the right way to talk about JNI directories with Gradle, as if I’m talking with CMake or GNUMake …