Ask Your Question
0

Trouble setting up NDK build [closed]

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

BenT gravatar image

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

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: '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!

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

Comments

What is your OpenCV version?

mshabunin gravatar imagemshabunin ( 2015-10-26 03:38:19 -0600 )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 Android.mk 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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

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

BenT gravatar image

important note to self: always put the Android.mk 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

2 followers

Stats

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

Seen: 1,872 times

Last updated: Oct 26 '15