通过动态交付功能加载opencv_java4.so文件时出错

问题描述 投票:0回答:1

我正在使用Android的动态投放功能,因为openCV会使应用程序尺寸过大。问题是当我尝试使用SplitInstallHelper.loadLibrary(this, "opencv_java4")加载opencv时。我给我这个错误。

致命异常:主要E AndroidRuntime:进程:com.example.com,PID:7470E AndroidRuntime:java.lang.UnsatisfiedLinkError:dlopen失败:未找到库“ libc ++ _ shared.so”E AndroidRuntime:位于java.lang.Runtime.loadLibrary0(Runtime.java:1016)E AndroidRuntime:位于java.lang.System.loadLibrary(System.java:1669)E AndroidRuntime:位于com.google.android.play.core.splitinstall.SplitInstallHelper.loadLibrary(未知来源:0)E AndroidRuntime:位于org.opencv.com.example.com.TempActivity.onResume(TempActivity.kt:615)E AndroidRuntime:位于android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1434)E AndroidRuntime:位于android.app.Activity.performResume(Activity.java:7304)E AndroidRuntime:位于android.app.ActivityThread.performResumeActivity(ActivityThread.java:3993)E AndroidRuntime:位于android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4033)E AndroidRuntime:位于android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)E AndroidRuntime:位于android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)E AndroidRuntime:位于android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)E AndroidRuntime:位于android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1977)E AndroidRuntime:位于android.os.Handler.dispatchMessage(Handler.java:106)E AndroidRuntime:位于android.os.Looper.loop(Looper.java:193)E AndroidRuntime:位于android.app.ActivityThread.main(ActivityThread.java:6923)E AndroidRuntime:位于java.lang.reflect.Method.invoke(本机方法)E AndroidRuntime:位于com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:493)E AndroidRuntime:位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)

我的[[onCreate看起来像这样

override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) try { SplitInstallHelper.loadLibrary(this, "opencv_java4") } catch (exception: Exception) { exception.printStackTrace() }
然后将

openCV库装入onResume

override fun onResume() { super.onResume() if (!OpenCVLoader.initDebug()) { OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION, this, mLoaderCallback) } else { mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS) } }
这是我<< openCV
模块的<< defaultConfig。

defaultConfig { externalNativeBuild { cmake { cppFlags "" arguments "-DANDROID_ARM_NEON=TRUE",'-DANDROID_STL=c++_shared' targets "opencv_jni_shared" } } ndk { abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' } } 某些资源要求对CMakeList.txt和dummy.cpp文件进行更改

CmakeList.txt

cmake_minimum_required(VERSION 3.6) # dummy target to bring libc++_shared.so into packages add_library(opencv_jni_shared STATIC dummy.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) target_link_libraries( # Specifies the target library. opencv_jni_shared # Links the target library to the log library # included in the NDK. ${log-lib})

dummy.cpp

#include <jni.h>
#include <string>

extern "C" JNIEXPORT jstring JNICALL
whatever(
    JNIEnv *env,
    jobject /* this */){
std::string hello = "Hello";
return env->NewStringUTF(hello.c_str());
};
android opencv unsatisfiedlinkerror dynamic-delivery
1个回答
0
投票
opencv_java4。

这是我对正在加载opencv的“活动”所做的更改。 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) SplitCompat.installActivity(this) //This is the line I added before loading "opencv_java4" SplitInstallHelper.loadLibrary(this, "c++_shared") SplitInstallHelper.loadLibrary(this, "opencv_java4") }

它成功了!

© www.soinside.com 2019 - 2024. All rights reserved.