1.我有一个现有的.so,由以下编译:
arm-linux-androideabi-g ++ * .cpp -o libshow_demo.so -fPIC -shared
2.然后我把它放到android studio3.0.1的项目文件夹中 the file structure
3.我在Android范围内编辑Gradle添加
sourceSets { 主要{ jniLibs.srcDir(['src / main / libs'])}}
4.然后我通过添加:
来编辑Cmakelists.txtadd_library( # Sets the name of the library.
show_demo
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
IMPORTED )
set_target_properties( # Specifies the target library.
show_demo
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
src/main/libs/libshow_demo.so )
include_directories( show_demo/include/ )
target_link_libraries( # Specifies the target library.
native-lib show_demo
# Links the target library to the log library
# included in the NDK.
${log-lib} )
5.AND来了这个bug。我不能做Gradle正确,它显示错误:
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process /Users/bertie/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/bertie/AndroidStudioProjects/Demo/app/.externalNativeBuild/cmake/debug/arm64-v8a --target native-lib}
ninja: error: 'src/main/libs/libshow_demo.so', needed by '../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so', missing and no known rule to make it
如何在android studio中使用共享对象? 努力,请告诉我该怎么做。谢谢你们:P
答案 0 :(得分:0)
根据您的标题和说明,我知道您只想将现有的共享对象库包含到APK中
为此,只需在 src / main / jniLibs / armeabi / libDummy.so 或 src / main / jniLibs / x86 / libDummy.so 添加库,具体取决于你想要和运行的架构!适合我:)