Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Trouble setting up NDK build

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: 'com.android.library'
import org.apache.tools.ant.taskdefs.condition.Os

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('com.android.library').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 Android.mk file like this:
PROJ_PATH   := $(call my-dir)
LOCAL_PATH  := $PROJ_PATH

include $(CLEAR_VARS)

include $(PROJ_PATH)/other_libs

OPENCV_DIR:=$(PROJ_PATH)/../../../../../OpenCV-android-sdk


OPENCV_INSTALL_MODULES:=off
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=LOCAL_SHARED
include $(OPENCV_DIR)/sdk/native/jni/OpenCV.mk

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

include $(BUILD_SHARED_LIBRARY)
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        : libusb100.so => libs/armeabi-v7a/libusb100.so
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 Application.mk 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!

click to hide/show revision 2
retagged

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

berak gravatar image

Trouble setting up NDK build

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: 'com.android.library'
import org.apache.tools.ant.taskdefs.condition.Os

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('com.android.library').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 Android.mk file like this:
PROJ_PATH   := $(call my-dir)
LOCAL_PATH  := $PROJ_PATH

include $(CLEAR_VARS)

include $(PROJ_PATH)/other_libs

OPENCV_DIR:=$(PROJ_PATH)/../../../../../OpenCV-android-sdk


OPENCV_INSTALL_MODULES:=off
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=LOCAL_SHARED
include $(OPENCV_DIR)/sdk/native/jni/OpenCV.mk

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

include $(BUILD_SHARED_LIBRARY)
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        : libusb100.so => libs/armeabi-v7a/libusb100.so
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 Application.mk 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!