0

1.I have a existing .so which is compiled by:

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

2.and then I put it into the project folder in android studio3.0.1 the file structure

3.I edit the Gradle under Android scope add

sourceSets{ main{ jniLibs.srcDir(['src/main/libs']) } }

4.then I edit Cmakelists.txt by adding:

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.AND here comes the bug.I can't do Gradle correct,It shows error:

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

How can I using shared object in android studio? Have try hard,Please tell me what to do.Thanks a lot:P

bbbbbbs
  • 1
  • 1
  • 1
    Have you built libshow_demo.so for arm64-v8a? If not, you have a choice to make: either build libshow_demo.so for *all* ABIs that you build your other shared libraries for, or *only* build the other shared libraries for the ABI that you've built libshow_demo.so for (by adding an abiFilter to your build script). – Michael Jan 05 '18 at 07:00
  • Your description is missing the key part, the file **/Users/bertie/AndroidStudioProjects/Demo/app/build.gardle**. Also, post the full content of **CMakeLists.txt**, this script needs fixes, too. – Alex Cohn Jan 08 '18 at 08:21

1 Answers1

1

From your title and description I get that you just want to include an existing shared object library into your APK

For this, just add the library at src/main/jniLibs/armeabi/libDummy.so or src/main/jniLibs/x86/libDummy.so depending on the architecture you want and run!! Works for me :)

abhiroxx
  • 116
  • 6