Ask Your Question

Trouble setting up NDK build [closed]

asked 2015-10-24 06:49:17 -0500

BenT gravatar image

updated 2015-10-24 07:19:17 -0500

berak gravatar image

Hi, I would like to use OpenCV in the NDK Part of my Android Project, but I can't get it to compile properly. I am using Android Studio and did the following steps: encouraged gradle to not generate a makefile, but to use mine instead:

apply plugin: ''

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    sourceSets {
        main {
            jniLibs.srcDir 'src/main/libs'
            jni.srcDirs = []

dependencies {
    compile fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild

task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
    println('executing ndkBuild')
    def ndkBuildingDir = project.plugins.findPlugin('').sdkHandler.getNdkFolder().absolutePath
    def ndkBuildPath = ndkBuildingDir
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndkBuildPath = ndkBuildingDir + '/ndk-build.cmd'
    } else {
        ndkBuildPath = ndkBuildingDir + '/ndk-build'
    commandLine ndkBuildPath, '-j8', '-C', file('src/main').absolutePath

Then I set up my file like this:
PROJ_PATH   := $(call my-dir)

include $(CLEAR_VARS)

include $(PROJ_PATH)/other_libs


include $(OPENCV_DIR)/sdk/native/jni/

LOCAL_SRC_FILES := UVCCamera/UVCPreview.cpp
LOCAL_MODULE     := libuvccamera
LOCAL_C_INCLUDES += $(OPENCV_DIR)/sdk/native/jni/include/
LOCAL_LDLIBS     += -llog -ldl

I am unsure on how to set LOCAL_SRC_FILES and LOCAL_C_INCLUDES. UVCCamera/UVCPreview.cpp includes opencv headers and the opencv include directory is stored in $(OPENCV_DIR)/sdk/native/jni/include/

Is this setup ok?

The problem I am having is that the ndk builder cant find the opencv header files, and I get an error:
jni/UVCCamera/UVCPreview.cpp:3:33: fatal error: opencv2/core/core.hpp: No such file or directory
[armeabi-v7a] Install        : => libs/armeabi-v7a/
make: *** No rule to make target `jni/libuvc/android/jni/../../UVCCamera/UVCPreview.cpp', needed by `obj/local/armeabi-v7a/objs/uvccamera/UVCCamera/UVCPreview.o'.  Stop.
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs/UVCCamera/UVCPreview.o] Error 1
[armeabi-v7a] Compile arm    : uvc_static <= stream.c
 #include <opencv2 core="" core.hpp="">
make: *** Waiting for unfinished jobs....

The "No rule to make target" disappears if I leave the LOCAL_SRC_FILES empty, but the builder still cant find the opencv headers.

Can anybody find an error in my setup?

The is basically the same as in the sample projects.

APP_PLATFORM := android-14
APP_ABI := armeabi-v7a
APP_OPTIM := release
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions

Thank you!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by BenT
close date 2015-10-26 06:55:42.342911


What is your OpenCV version?

mshabunin gravatar imagemshabunin ( 2015-10-26 03:38:19 -0500 )edit

Hi. I used the latest version. Actually I solved this yesterday evening, but I am not allowed to post my answer for another few hours since I am new to the forum. The error was that I had the include in the wrong file, it was supposed to be in the subdirectory UVCCamera, where the source file that uses opencv is.

BenT gravatar imageBenT ( 2015-10-26 04:01:27 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-10-26 06:53:56 -0500

BenT gravatar image

important note to self: always put the file in the right folder. I put the file in the subdirectory UVCCamera where the code that uses opencv is and it is working now. Includes are fine and I can use opencv on ndk level finally!

edit flag offensive delete link more

Question Tools



Asked: 2015-10-24 06:49:17 -0500

Seen: 1,695 times

Last updated: Oct 26 '15