我正在为三星Galaxy A5 2016开发原生应用。 当我将ABI设置为armabi-v7a时,该应用程序正常工作。现在我想提高本机操作的速度,因此我尝试将ABI设置为arm64-v8a。由于我的手机使用Cortex-A53 CPU,这应该没问题,但是当我运行应用程序时,我得到以下异常:
08-21 19:18:11.251 9743-9743/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: tum.ei.lmt.orbslamapp, PID: 9743
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/tum.ei.lmt.orbslamapp-1/base.apk"],nativeLibraryDirectories=[/data/app/tum.ei.lmt.orbslamapp-1/lib/arm, /data/app/tum.ei.lmt.orbslamapp-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]] couldn't find "libnative-lib.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:972)
at java.lang.System.loadLibrary(System.java:1567)
at tum.ei.lmt.orbslamapp.NativeInterface.<clinit>(NativeInterface.java:6)
at tum.ei.lmt.orbslamapp.MainActivity.onCameraViewStarted(MainActivity.java:234)
at org.opencv.android.CameraBridgeViewBase.processEnterState(CameraBridgeViewBase.java:323)
at org.opencv.android.CameraBridgeViewBase.checkCurrentState(CameraBridgeViewBase.java:313)
at org.opencv.android.CameraBridgeViewBase.surfaceChanged(CameraBridgeViewBase.java:198)
at android.view.SurfaceView.updateWindow(SurfaceView.java:668)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:172)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1013)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2555)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1550)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7190)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:959)
at android.view.Choreographer.doCallbacks(Choreographer.java:734)
at android.view.Choreographer.doFrame(Choreographer.java:670)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:945)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
似乎PathClassLoader找不到libnative-lib。 这是Gradle构建控制台的一小部分:
Build native-lib arm64-v8a
[1/13] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/featureCompression/DBoW2/FeatureVector.cpp.o
[2/13] Building CXX object CMakeFiles/native-lib.dir/src/main
...
[13/13] Linking CXX shared library ../../../../build/intermediates/cmake/release/obj/arm64-v8a/libnative-lib.so
有谁知道我如何告诉ClassPathLoader libnative-lib.so在哪里或帮助我提出任何其他建议。 谢谢。
我的gradle文件的有趣部分:
externalNativeBuild {
cmake {
arguments "-DANDROID_NATIVE_API_LEVEL=24", "-DANDROID_ABI=arm64-v8a", "-DCMAKE_BUILD_TYPE=Release", "-DANDROID_ARM_NEON=TRUE"
cppFlags "-std=c++11 -frtti -fexceptions -DNDEBUG -std=gnu++0x -Wno-deprecated -ftree-vectorize -ffast-math"
//abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
//abiFilters 'armeabi-v7a', 'arm64-v8a'
abiFilters 'arm64-v8a'
}
}
整个CMakeLists文件:
cmake_minimum_required(VERSION 3.4.1)
include_directories(/home/alex/Android/OpenCV-android-sdk/sdk/native/jni/include)
add_library(opencv-lib SHARED IMPORTED)
set_target_properties(opencv-lib PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jni/${ANDROID_ABI}/libopencv_java3.so)
add_library( # Sets the name of the library.
native-lib
SHARED
src/main/cpp/NativeInterface.cpp
...
src/main/cpp/featureCompression/DUtils/Timestamp.cpp
)
target_compile_options(native-lib PUBLIC
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O3>"
)
find_library( # Sets the name of the path variable.
log-lib
log )
target_link_libraries( # Specifies the target library.
native-lib
opencv-lib
${log-lib} )