我正在尝试在我的android应用程序中使用来自另一个存储库(已经准备好使用本机代码)的本机代码。所以我需要将libs output文件夹和java文件从这个存储库放到我的项目中。我遵循了以下程序:
从以前构建的存储库开始:
修改了文件夹结构以及所有相关的源代码文件,以确保包名与我当前的应用程序目标完全匹配。
确保安装了android ndk并包含在path环境变量中。运行“ndk build-b ndk\u debug=0”。已在libs文件夹中获取已编译的库。
将整个libs文件夹(包括我的应用程序项目app\src\main下的所有子文件夹和内容)以及src/the/package/name下的所有java源代码(demo activity类除外)复制到我的应用程序项目的相应位置。
在模块的build.gradle中添加了以下行:
sourceSets.main {
jni.srcDirs = [] // disable automatic ndk-build call
jniLibs.srcDir 'src/main/libs/' // integrate your libs from libs instead of jniLibs
}
在我的应用程序中调用复制的java文件中的方法时,出现以下错误:
2021-01-07 09:33:21.304 15856-15856/com.example.wbd_tws_demo E/le.wbd_tws_dem: No implementation found for void com.example.wbd_tws_demo.AndroidHRVAPIJNI.init_hrv_analysis() (tried Java_com_example_wbd_1tws_1demo_AndroidHRVAPIJNI_init_1hrv_1analysis and Java_com_example_wbd_1tws_1demo_AndroidHRVAPIJNI_init_1hrv_1analysis__)
2021-01-07 09:33:21.305 15856-15856/com.example.wbd_tws_demo D/AndroidRuntime: Shutting down VM
2021-01-07 09:33:21.305 15856-15856/com.example.wbd_tws_demo W/le.wbd_tws_dem: Accessing hidden method Lcom/msic/qarth/PatchStore;->createDisableExceptionQarthFile(Ljava/lang/Throwable;)Z (blacklist, JNI)
2021-01-07 09:33:21.305 15856-15856/com.example.wbd_tws_demo E/le.wbd_tws_dem: [qarth_debug:] get PatchStore::createDisableExceptionQarthFile method fail.
2021-01-07 09:33:21.306 15856-15856/com.example.wbd_tws_demo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.wbd_tws_demo, PID: 15856
java.lang.UnsatisfiedLinkError: No implementation found for void com.example.wbd_tws_demo.AndroidHRVAPIJNI.init_hrv_analysis() (tried Java_com_example_wbd_1tws_1demo_AndroidHRVAPIJNI_init_1hrv_1analysis and Java_com_example_wbd_1tws_1demo_AndroidHRVAPIJNI_init_1hrv_1analysis__)
at com.example.wbd_tws_demo.AndroidHRVAPIJNI.init_hrv_analysis(Native Method)
at com.example.wbd_tws_demo.AndroidHRVAPI.init_hrv_analysis(AndroidHRVAPI.java:17)
at com.example.wbd_tws_demo.BleOperations.onCreate(BleOperations.java:57)
at android.app.Activity.performCreate(Activity.java:7458)
at android.app.Activity.performCreate(Activity.java:7448)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1286)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3409)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
at android.os.Handler.dispatchMessage(Handler.java:112)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
我不知道为什么会出现这个错误。我已经检查了其他答案的解决方案,并尝试了他们,没有任何运气。另外,我也不知道为什么在这个错误中,它说“尝试了java\u com\u example\u wbd\u 1tws\u 1demo\u androidhrvapijni\u init\u 1hrv\u 1analysis”。为什么1在那里?我的包名是com.example.wbd\u tws\u demo。1正常吗?
暂无答案!
目前还没有任何答案,快来回答吧!