How to set the path for C / C ++ using Gradle Experimental Plugin?

Android Studio cannot find my header files when they are in a different place than the main source folder of my module. This is noticeable with the #include "SDL_config.h" commands highlighted in red (other #include instructions are good).

I tried to change the values โ€‹โ€‹of cppFlags below, but I begin to doubt that these cppFlags are even passed to the compiler in general.

Has anyone been able to include files from folders other than their main source folder?

Is there a problem with the way I pointed out cppFlags or perhaps the module name or even the sources?

I could go through the SDL2 source and change all #include statements to relative #include paths, but I really don't want to change the SDL2 source. I should just list the included paths in some way.

apply plugin: 'com.android.model.application' model { ... android.ndk { moduleName = 'main' //W:\hello-sdl-android\android-project\app\src\main\jni\SDL2\include cppFlags += "-I${file("src/main/jni/SDL2/include")}".toString() cppFlags += "-I${file("src/main/jni/SDL2/src")}".toString() } android.sources { main.jni { source { srcDirs += ['src/main/jni/src'] srcDirs += ['src/main/jni/SDL2/src'] } } } ... } 

UPDATE: Here is more information about my current project layout:

application / SRC / main / JNI app / src / main / jni / src / Main.cpp <- This is a compilation of app / src / main / jni / SDL2 <- All SDL2 sources are here app / src / main / jni / GLM < - Here are all GLM sources

This layout is the direct result of using the sample project I provided here: https://gitlab.com/scannerdarkly/hello-sdl-android

This project will be built using ndk-build from the command line - I wanted to take a step further by building in Android Studio. My project will try to draw a triangle on a GLES2 device.

Here is the link to my current project:

http://www.mediafire.com/download/92577p7vf123l72/hello-sdl-android.zip

+6
source share
4 answers

Yes! I realized this - the SDL2 source files are .C files, so include paths must be declared using CFlags, not cppFlags.

+2
source

I use a slightly different approach:

 cFlags += "-I" + file("src/main/jni/SDL2/include").absolutePath 

.. and it works. Probably the reason is that the compiler starts with a different working directory, and absolutePath removes any ambiguity here.

+9
source

Here is another style for more header paths using the experimental gradle plugin, an example with openssl and some abc library:

 // compile parameters // include openssl headers C (if you have C files) CFlags.add("-isystem${project.rootDir}/external-libraries/openssl/openssl-1.0.2g/include".toString()) // include openssl headers C++ (if you have cpp files) cppFlags.add("-isystem${project.rootDir}/external-libraries/openssl/openssl-1.0.2g/include".toString()) // include abc headers C (if you have C files) CFlags.add("-I${project.rootDir}/external-libraries/abc/abc-5.5/include".toString()) // include abc headers C++ (if you have cpp files) cppFlags.add("-I${project.rootDir}/external-libraries/abc/abc-5.5/include".toString()) // linking parameters // link libcrypto.so ldFlags.add("-L${project.rootDir}/external-libraries/openssl/openssl-1.0.2g/lib/armeabi-v7a".toString()) ldLibs.add('crypto') // link libabc.so ldFlags.add("-L${project.rootDir}/external-libraries/abc/abc-5.5/lib".toString()) ldLibs.add('abc') 
+1
source

for many header paths:

 cFlags = "-I" + file("src/main/jni/path1").absolutePath + " -I" + file("src/main/jni/path2").absolutePath + " -I" + file("src/main/jni/path3").absolutePath 
0
source

All Articles