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