【问题标题】:How to using existing .so in android studio?如何在android studio中使用现有的.so?
【发布时间】:2018-01-05 03:06:00
【问题描述】:

1.我有一个现有的.so,由以下人员编译:

arm-linux-androideabi-g++ *.cpp -o libshow_demo.so -fPIC -shared

2.然后我把它放到android studio3.0.1的项目文件夹中 the file structure

3.我在Android范围内编辑Gradle添加

源集{ 主要的{ jniLibs.srcDir(['src/main/libs']) } }

4. 然后我编辑 Cmakelists.txt 添加:

add_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.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

【问题讨论】:

  • 你为 arm64-v8a 构建了 libshow_demo.so 吗?如果没有,您可以选择:为 all 您构建其他共享库的 ABI 构建 libshow_demo.so,或 only 构建其他共享库您为其构建 libshow_demo.so 的 ABI(通过在构建脚本中添加 abiFilter)。
  • 您的描述缺少关键部分,即文件 /Users/bertie/AndroidStudioProjects/Demo/app/build.gardle。另外,贴出CMakeLists.txt的完整内容,这个脚本也需要修复。

标签: android-studio android-ndk shared-libraries shared-objects


【解决方案1】:

根据您的标题和描述,我知道您只想将现有的共享对象库包含到您的 APK 中

为此,只需在 src/main/jniLibs/armeabi/libDummy.sosrc/main/jniLibs/x86/libDummy.so 中添加库,具体取决于您想要并运行的架构!为我工作:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多