Android OpenCV未定义对本机类的引用

时间:2017-02-25 18:39:07

标签: android c++ opencv android-ndk

我在openCv引用中创建我的android项目并配置我的项目,在SDK中添加java作为模块并在jinLibs中复制所有库(不同的CPU类型)!我有一个名为libdetection_based_tracker

的本地类

当我尝试构建我的项目时,我遇到了这个例外:

CMakeFiles/libdetection_based_tracker.dir/src/main/cpp/libdetection_based_tracker.cpp.o: In function `Java_ir_whiteapp_maremat_DetectionBasedTracker_nativeCreateObject':
G:\AR\Maremat\app\src\main\cpp/libdetection_based_tracker.cpp:28: undefined reference to `DetectionBasedTracker::Parameters::Parameters()'
G:\AR\Maremat\app\src\main\cpp/libdetection_based_tracker.cpp:31: undefined reference to `DetectionBasedTracker::DetectionBasedTracker(std::string const&, DetectionBasedTracker::Parameters const&)'
CMakeFiles/libdetection_based_tracker.dir/src/main/cpp/libdetection_based_tracker.cpp.o: In function `Java_ir_whiteapp_maremat_DetectionBasedTracker_nativeSetFaceSize':
G:\AR\Maremat\app\src\main\cpp/libdetection_based_tracker.cpp:64: undefined reference to `DetectionBasedTracker::getParameters()'
G:\AR\Maremat\app\src\main\cpp/libdetection_based_tracker.cpp:66: undefined reference to `DetectionBasedTracker::setParameters(DetectionBasedTracker::Parameters const&)'
CMakeFiles/libdetection_based_tracker.dir/src/main/cpp/libdetection_based_tracker.cpp.o: In function `cv::Mat::operator=(cv::Mat const&)':

这是我的app level gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "ir.whiteapp.maremat"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.1'
    testCompile 'junit:junit:4.12'
    compile project(':openCVLibrary320')
}

和我的CmakeList

cmake_minimum_required(VERSION 3.4.1)

include_directories(src/main/jniLibs/jni/include)
add_library( lib_opencv SHARED IMPORTED )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION  ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
add_library( native-lib SHARED src/main/cpp/native-lib.cpp )
add_library( libdetection_based_tracker SHARED src/main/cpp/libdetection_based_tracker.cpp )

find_library( # Sets the name of the path variable.
          log-lib

          # Specifies the name of the NDK library that
          # you want CMake to locate.
          log )

target_link_libraries( # Specifies the target library.
                   native-lib

                   # Links the target library to the log library
                   # included in the NDK.
                   ${log-lib} )

整个项目是here没有jinLibs文件!这是我第一次尝试使用NDK和OpenCV,然后问我问题的一部分是否含糊不清!

1 个答案:

答案 0 :(得分:0)

根据this,Android.mk必须如下所示:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := asmlibrary

LOCAL_SRC_FILES := so/$(TARGET_ARCH_ABI)/libasmlibrary.so #must be included
include $(PREBUILT_SHARED_LIBRARY) 

include $(CLEAR_VARS)

#OPENCV_CAMERA_MODULES:=off
#OPENCV_INSTALL_MODULES:=off
#OPENCV_LIB_TYPE:=SHARED

include /youropencv/OpenCV-2.4.6-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_SRC_FILES  := DemoFit.cpp

LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_CFLAGS    += -DOPENCV_OLDER_VISION #(if still get errors, disable OPENCV_OLDER_VISION )

LOCAL_LDLIBS     += -llog -ldl  

LOCAL_MODULE     := jni-asmlibrary

LOCAL_SHARED_LIBRARIES := asmlibrary

include $(BUILD_SHARED_LIBRARY)