[英]Android studio CMake does not link the prebuilt library to the main .so file
I eventually cross-compiled a capstone library for android, but now I am having trouble linking it with my main .so
library(native-lib). 我最终为Android交叉编译了一个capstone库 ,但是现在我无法将其与我的主要
.so
库(native-lib)链接。 I followed the steps shown in the official web site . 我按照官方网站上显示的步骤进行操作。
My CMakeList.txt is as below. 我的CMakeList.txt如下。
# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.
cmake_minimum_required(VERSION 3.4.1)
# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add.library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.
add_library( # Specifies the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
find_library( # Defines the name of the path variable that stores the
# location of the NDK library.
log-lib
# Specifies the name of the NDK library that
# CMake needs to locate.
log )
# Links your native library against one or more other native libraries.
#target_link_libraries( # Specifies the target library.
# native-lib
#
# # Links the log library to the target library.
# ${log-lib} )
add_library( capstone
SHARED
IMPORTED )
set_target_properties( # Specifies the target library.
capstone
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
C:/Users/82102/AndroidStudioProjects/Android-Disassembler/capstone/${ANDROID_ABI}/libcapstone.so.5 )
target_link_libraries( native-lib capstone ${log-lib} ) #app-glue
include_directories( capstone/include/ )
The APK built has native-lib.so
, but does not have 'libcapstone.so or
libcapstone.so.5`. 内置的APK具有
native-lib.so
,但没有'libcapstone.so or
libcapstone.so.5'。 So when I launch the APK, the error below happens. 因此,当我启动APK时,会发生以下错误。
2019-08-22 14:21:01.340 6122-6122/com.kyhsgeekcode.disassembler E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kyhsgeekcode.disassembler, PID: 6122
java.lang.UnsatisfiedLinkError: dlopen failed: library "libcapstone.so.5" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
at java.lang.System.loadLibrary(System.java:1669)
at com.kyhsgeekcode.disassembler.MainActivity.<clinit>(MainActivity.java:169)
at java.lang.Class.newInstance(Native Method)
I tried adding a jniLibs
directory in the folder and adding the libcapstone.so.5, but the APK built still does not contain libcapstone.so.(5) and the same error happens. 我尝试在文件夹中添加
jniLibs
目录并添加libcapstone.so.5,但是构建的APK仍然不包含libcapstone.so。(5),并且发生相同的错误。
How should I edit my CMakeList.txt to correctly link a custom prebuilt library to a main shared library?(native-lib.so) 我应如何编辑CMakeList.txt以将自定义的预构建库正确链接到主共享库?(native-lib.so)
I changed my CMakeLists.txt to link the capstone as a static library. 我将CMakeLists.txt更改为将顶点链接为静态库。
# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.
cmake_minimum_required(VERSION 3.4.1)
# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add.library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.
add_library( # Specifies the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
find_library( # Defines the name of the path variable that stores the
# location of the NDK library.
log-lib
# Specifies the name of the NDK library that
# CMake needs to locate.
log )
# Links your native library against one or more other native libraries.
#target_link_libraries( # Specifies the target library.
# native-lib
#
# # Links the log library to the target library.
# ${log-lib} )
#add_library( capstone
# SHARED
# IMPORTED )
#set_target_properties( # Specifies the target library.
# capstone
#
# # Specifies the parameter you want to define.
# PROPERTIES IMPORTED_LOCATION#
#
# # Provides the path to the library you want to import.
# C:/Users/82102/AndroidStudioProjects/Android-Disassembler/capstone/${ANDROID_ABI}/libcapstone. )
target_link_libraries( native-lib C:/Users/82102/AndroidStudioProjects/Android-Disassembler/capstone/${ANDROID_ABI}/libcapstone.a ${log-lib} ) #app-glue
include_directories( capstone/include/ )
Hopefully, it worked! 希望它能奏效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.