Using a prebuilt shared Library in Android Studio (cmake)

左心房为你撑大大i 提交于 2019-12-04 06:33:48

The prebuilt libLibrary.so does not have SONAME. If for whatever reason you cannot rebuild this library with latest NDK, you may try the patchelf utility to add SONAME to existing binary.

To package the prebuilt library into your APK, you need to manually configure Gradle with the sourceSets block to include the path to your .so file. After building your APK, you can verify which libraries Gradle packages into your APK by using the APK Analyzer(Build>Analyze APK...).

android {
...
sourceSets {
    main {
        jniLibs.srcDirs 'imported-lib/src/', 'more-imported-libs/src/'
    }
}

for more information please see here "Include prebuilt native libraries"

You don't need to use CMake to use shared libraries (.so files). Just place the libraries inside the respective directories in src/main/jniLibs directory. Then you can load the libraries directly.

Android studio may show error in the native method declarations but, your app will work fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!