As I have written in a recent post, I migrated an android project to gradle and had to add NDK build steps there. It worked well, until I upgraded the Android Studio to 0.4.0, which triggered an update to gradle 1.9, which triggered an update to 0.7.0. I had a few issues to resolve after that. Read on to know how to resolve them if you’re in the same situation.
Unfortunately, in my project the C++ sources are located outside the Android project directory, so the modules’ .mk files have these relative links: LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../../libs/lib1/include. Now the build fails with errors of not found includes:
FAILURE:Buildfailedwithanexception.*Whatwentwrong:Executionfailedfortask':project:compileDebugNdk'.>com.android.ide.common.internal.LoggedErrorException:Failedtoruncommand:…/android-ndk-r9/ndk-buildNDK_PROJECT_PATH=nullAPP_BUILD_SCRIPT=…/project/build/ndk/english/debug/Android.mkAPP_PLATFORM=android-8NDK_OUT=…/project/build/ndk/english/debug/objNDK_LIBS_OUT=…/project/build/ndk/english/debug/libAPP_ABI=allErrorCode:2Output:…/project/src/main/jni/main.cpp:10:71: fatal error: ../../../libs/lib1/include/header.hpp: No such file or directory compilation terminated. make: *** […/project/build/ndk/english/debug/obj/local/x86/objs/project/…/project/src/main/jni/main.o] Error 1 make: *** Waiting for unfinished jobs.... …/project/src/main/jni/main.cpp:10:71:fatalerror:../../../libs/lib1/include/header.hpp:Nosuchfileordirectory…/project/src/main/jni/main.cpp:10:71: fatal error: ../../../libs/lib1/include/header.hpp: No such file or directorycompilation terminated. compilation terminated. …/project/src/main/jni/main.cpp:10:71:fatalerror:../../../libs/lib1/include/header.hpp:Nosuchfileordirectorycompilationterminated.make:***[…/project/build/ndk/english/debug/obj/local/armeabi/objs/project/…/project/src/main/jni/main.o]Error1make:***[…/project/build/ndk/english/debug/obj/local/armeabi-v7a/objs/project/…/project/src/main/jni/main.o]Error1make:***[…/project/build/ndk/english/debug/obj/local/mips/objs/project/…/project/src/main/jni/main.o]Error1
The plugin copies the jni/ directory into the build directory and tries to build it there. That’s the correct approach, but the include paths are wrong then. So to avoid NDK building with the plugin and use the old way instead, I renamed the jni/ dir into native/, and had to add extra parameters to the build command (the buildNative task):