问题描述
现在,Android Studio 2.2正式发布了,我正在从旧的ndk-build进程中迁移,以尝试在AS中使用CMake.由于我要整合公司内部(我无法编辑)的几个代码库,这些代码库大量使用C ++ 11代码(包括可怕的std :: to_string()方法),因此唯一可以编译的方法是选择一些配置选项-我在开始使用ndk-build时就已经发现了所有这些选项. (请参见下文)
Now that Android Studio 2.2 is released officially, I'm migrating from my old ndk-build process to try and use CMake within AS. As I'm incorporating several codebases from within my company (that I can't edit) that make heavy use of C++11 code (including the dreaded std::to_string() method), the only way I can compile is with a select few configuration options - all of which I discovered earlier when beginning work with ndk-build. (see below)
因此,所有内容再次编译并构建到APK中-我100%验证了我的输出共享库是否存在于APK中,但我无法成功使用System.loadLibrary('mylibrary')
-事实证明,这是因为依赖项 libc ++ _ shared.so 丢失.
So everything compiles again and builds into the APK - and I 100% verify that my output shared library exists in the APK, but I'm unable to successfully use System.loadLibrary('mylibrary')
- and it turns out this is because the dependency libc++_shared.so is missing.
在这种情况下,出现以下错误:
As in, I get the following error:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
在旧的ndk构建过程中,我总是在输出文件夹中使用2个库( mylibrary.so 和 libc ++ _ shared.so ),从而将其捆绑到应用程序中.看来CMake工具链根本没有捆绑 libc ++ _ shared.so (实际上,在APK中找不到).
In my old ndk-build process, I always wound up with the 2 libraries (mylibrary.so and libc++_shared.so) in my output folder, which thereby got bundled together into the app. It seems the CMake toolchain isn't bundling libc++_shared.so at all (indeed, it's not found in the APK).
我已经为此努力了6个小时.我可以以某种方式使CMake工具链捆绑此缺少的库吗?有任何线索吗?
I've been banging my head on this for 6 hours. Can I somehow get the CMake toolchain to bundle this missing library? Any clues?
.
.
我的设置:
在gradle.build中:
In gradle.build:
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared', '-DANDROID_TOOLCHAIN=gcc', '-DANDROID_PLATFORM=android-16'
}
}
还有我的CMakeLists.txt(为简洁起见,删除了文件名):
And my CMakeLists.txt (filenames cut out for brevity):
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=gnu++11")
include_directories(.)
include_directories(./other)
set(my_SRCS jniInterface.cpp
etc.cpp)
add_library(mylibrary SHARED ${my_SRCS})
target_link_libraries(mylibrary atomic log)
推荐答案
我写了一个CMake配置,该配置应打包STL文件: https://github.com/jomof/ndk- stl/blob/master/ndk-stl-config.cmake
I wrote a CMake config that should package the STL files:https://github.com/jomof/ndk-stl/blob/master/ndk-stl-config.cmake
将此文件复制到CMakeLists.txt
旁边并在CMakeLists.txt
内部
Copy this file next to your CMakeLists.txt
and inside CMakeLists.txt
do
include(ndk-stl-config.cmake)
让我知道您是否有问题
这篇关于Android Studio CMake-共享库缺少libc ++ _ shared.so? CMake可以捆绑吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!