2

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

Galaxy
  • 1,129
  • 11
  • 27

2 Answers2

0

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.

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
0

Android Studio gradle-experimental plugin uses ${app}/src/main/jni as default for native code, and the processing is recursive: all sub-directories will be included to build native shared lib. If there is some specific file(s) you do not want, you could try "exclude" as in:
https://github.com/googlesamples/vulkan-basic-samples/blob/master/LunarGSamples/Demos/Hologram/android/build.gradle

Note that exclude is for file name, does not matter in which directory it sits or having multiple file of the same name. In the above link, it also includes source code from other directories NOT inside "jni" folder.

You may also see this example:
https://github.com/googlesamples/android-ndk/tree/master/Teapot/app/src/main/jni it builds and runs, have sub-directory under jni too, but does not use "exclude".

Your issue might be something else, Android Studio could handle nested directories. If you could add a ling to your code, that would be great.

Gerry
  • 1,223
  • 9
  • 17