Android Studio 2.2链接OPENCV静态库
Android Studio 2.2 link opencv static libraries
我正在尝试将Android Studio 2.2中的OpenCV本机Libs链接起来。我发现的所有主题都使用android.mk文件或build.gradle文件中Android Studio找不到的其他方法。
我正在使用Android Studio 2.2,并通过使用C 支持的新项目来创建项目。
到目前为止,我成功地在C 源文件中加入了OpenCV库:
#include <jni.h>
#include <string>
#include "opencv.hpp"
extern "C"
jstring
Java_com_rvstudios_roomscanner_capp_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
cv::Mat image;
cv::cvtColor(image, image, CV_BGR2GRAY);
return env->NewStringUTF(hello.c_str());
}
当我尝试构建它时,我会在OpenCV函数上获得未定义的参考错误,这是因为必须链接静态库(.A文件)。从我已经阅读的内容来看,这应该在build.gradle文件中完成。
这是我到目前为止的build.gradle文件:
apply plugin: 'com.android.application'
def targetPlatform = "mips"
android {
compileSdkVersion 23
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.rvstudios.roomscanner.capp"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
cppFlags.add("-isystem${project.rootDir}/app/src/main/cpp/vision".toString())
}
}
}
sourceSets.main {
jni.srcDirs = ["${project.rootDir}/app/src/main/jniLibs/${targetPlatform.toString()}/"]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
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:23.4.0'
compile 'com.android.support:design:23.4.0'
testCompile 'junit:junit:4.12'
}
我被困在这里,因为我不知道如何链接静态库。我已经看到了许多关于同一问题的主题,但是我阅读的所有内容都使用了不同的项目设置,而且我是Android开发的新主题,因此我根本不知道它。
edit1:我的cmakelists.txt:
# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
src/main/cpp/native-lib.cpp
src/main/cpp/vision/opencv.hpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
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 )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib}
)
to cmakelists.txt,add:
set(pathToOpenCV /Users/admin/Projects/OpenCV-android-sdk/sdk/native/) // Replace with your OpenCV SDK path
include_directories(${pathToOpenCV}/jni/include)
相关文章:
- 如何在 docker 中使用静态 opencv 库编译 c++ 应用程序
- 将本地 OpenCV Mat 变量声明为静态以防止重新分配
- 如何使用cmake设置OpenCV以启用动态和静态构建
- OpenCV噪声消除静态摄像机的视频
- 尽管有静态链接,Opencv 3.2.0 .dll丢失
- Android Studio 2.2链接OPENCV静态库
- 在Windows上运行的Eclipse上静态链接OpenCV
- openCV 243 使用静态库错误LNK2019
- 静态 opencv 在 Arm Linux busybox 上找不到 USB 网络摄像头
- 使用 TDM-GCC-64、Cmake 和 CodeBlock 在 Windows 8 中构建 OpenCV 静态库时出
- Ubuntu上的OpenCv静态编译
- 将 opencv 捆绑为静态库会提供数千个未定义的引用
- 使用多线程调试 DLL (/MDd) C 运行时库生成静态 Opencv 库
- 调用静态 opencv 库
- 如何将 OpenCV 2.4 静态库与 Visual Studio 配合使用
- 在我的CMake项目中使用静态构建而不是OpenCV的共享构建
- Android Studio链接OpenCV静态库
- OpenCV和Visual Studio 2015:为什么包含静态库不起作用
- Opencv静态链接给出错误
- 静态OpenCV库中未定义的引用