This project is created from opencv, with the helper script from eclipse2as.sh
buildscript {
//...
dependencies {
//...
classpath 'com.ydq.android.gradle.build.tool:nativeBundle:1.0.4'
//...
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.ydq.android.gradle.native-aar.import'
dependencies {
//...
implementation 'com.wanghong.opencv:opencv-with-header:3.1.1-dev'
//...
}
- Create a reference in your
CMakeLists.txt
if you usecmake
build system
include (${ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK})
target_link_libraries(native-lib ${ANDROID_GRADLE_NATIVE_MODULES})
Check the information from here if you use other build system
- Verify in your code
#include <jni.h>
#include <string>
#include <opencv/cv.h>
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_myapp_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++" + cv::getBuildInformation();
return env->NewStringUTF(hello.c_str());
}
- Enjoy!
gnustl_static
has been removed started from ndk r18, so make sure you use ndk version before r18 release.
- Many thanks to this header bundle plugin, it's hard to config and use in newer android studio without this plugin