参考资料:
https://blog.csdn.net/qq_25884515/article/details/104250920
创建C++项目
理解 CMakeList.txt文件,
设置头文件 和 添加源文件
#设置头文件为当前路径
INCLUDE_DIRECTORIES("./")
# 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 them 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).
native-lib.cpp
v4l2Cocos.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 )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# 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} )
在 JAVA 文件中 定义 调用的 函数 参数 和返回数据
public native String stringFromJNI();
public native int getFrameFromJNI(int[] data);
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}
在C++文件中 写入这些函数的实现
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_seziocr_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
char pbuf[128];
pCap=new CapCocos();
int d=pCap->OpenVideo("/dev/video0");
sprintf(pbuf,"video0:%d",d);
LOGD("Hello World %d",d);
//return env->NewStringUTF(hello.c_str());
return env->NewStringUTF(pbuf);
}
注意 env 是链接 c++ 和 java 的数据格式转换的 重要参数
还要研究怎么 直接调用 so 的库 不需要些 源码