Android studio jni cmake 调用第三方so
1.引用第三方so
main下创建jniLibs并导入so
配置makelist
#依赖的add库 add_library(addccc STATIC IMPORTED) #添加预编译静态库,只需要告诉CMAKE导入项目即可 set_target_properties( # Specifies the target library. addccc # Specifies the parameter you want to define. PROPERTIES IMPORTED_LOCATION # Provides the path to the library you want to import. ${CMAKE_SOURCE_DIR}/../jniLibs/armeabi-v7a/libaddccc.so )
#加入库
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib}
addccc #加入
)
引用库
static { System.loadLibrary("addccc"); System.loadLibrary("native-lib"); }
public native int add(int a,int b);
cpp调用/测试
//先声明一下so里的方法 extern int addsss(int a,int b); extern "C" JNIEXPORT jint JNICALL Java_com_dyzx_test_MainActivity_add(JNIEnv *env, jobject thiz, jint a, jint b) { return addsss(a,b); }
问题
1.More than one file was found with OS independent path 'lib/armeabi-v7a/libaddccc.so'. If you are using jniLibs and CMake IMPORTED targets,
app->build.gradle
android { ... // Fix: More than one file was found packagingOptions { pickFirst 'lib/armeabi-v7a/libaddccc.so' } }
第二种 去掉这个
sourceSets.main { jniLibs.srcDirs = ['libs/'] }
2.linux平台的so不能直接在Android 使用
3.
本文来自博客园,作者:西瓜皮不甜,转载请注明原文链接:https://www.cnblogs.com/Jieth/p/14925475.html