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.