hxpax hxpax - 5 months ago 15
Android Question

How to set up JNI sub directories in Android Studio

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 ...

Answer

AS will by default compile all C/C++ files under jni directory. If you need more control, either use the experimental plugin, or disable the built-in task and run ndk-build, see define LOCAL_SRC_FILES in ndk{} DSL for example.

Comments