5

I tried to add library into project, but android studio ignore my lib. My CmakeLists.txt add_library( mylib SHARED IMPORTED ) set_target_properties(ffmpeg PROPERTIES IMPORTED_LOCATION src/main /libs/${ANDROID_ABI}/libmylib.so )

After building my apk not contain libmylib.so. How to add prebuilt library into project with cmake?

streit
  • 93
  • 1
  • 2
  • 6
  • Possible duplicate of [How to include \*.so library in Android Studio?](https://stackoverflow.com/questions/24357687/how-to-include-so-library-in-android-studio) – Ciro Santilli OurBigBook.com Nov 29 '17 at 17:41
  • add a .so file from directory outside android project: https://stackoverflow.com/questions/50713933/add-so-prebuilt-library-from-another-directory-to-apk – user1506104 Jun 11 '18 at 17:27

2 Answers2

7

currently need to pack it by the app. it could be something like:

    sourceSets {
        main {
            // let gradle pack the shared library into apk
            jniLibs.srcDirs = ['point/to/your/shared-lib']
       }
    }

one example is: https://github.com/googlesamples/android-ndk/blob/master/hello-libs/app/build.gradle If your shared lib [yours is inside project path] is close to your project, put relative path of your shared-lib to your CMakeLists.txt would work.

Some background discussion at the bottom of this bug might help: https://code.google.com/p/android/issues/detail?id=214664&can=8&q=vulkan&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened

Gerry
  • 1,223
  • 9
  • 17
  • Can I ask how this deals with multiple ABIs? Do they need to be individually specified or can you simply point to the base directory that contains builds for different architectures? – Luther Apr 16 '18 at 18:22
  • for multiple ABIs, your-shared-lib-directory should have abi directories(put there by you) like x86, x86_64, arm64-v8a, armeabi-v7a; gradle would merge them into your final APK automatically. – Gerry Apr 26 '18 at 21:57
2

1 - In the root directory, create new folder: /libs in which and place your external libraries in there.

2 - Change the project structure

yourprojectname/
      app/
           - build.gradle  // Local Gradle configuration (for app only)
           ...
      libs/
           libraryName/
                - build.gradle // Local Gradle configuration (for library only)
      - build.gradle // Global Gradle configuration (for whole project)
      - settings.gradle
      - gradle.properties
      ...

3 - don't forget to change gradle.setting to

include ':app', ':libraryName'
project(':libraryName').projectDir = new File('libs/libraryName')

4-In app/build.gradle add your library

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(":PagerSlidingTabStrip")
}

Also there is way in android studio to add your library so it config gradle and project structure and it is :

1.File / Project Structure /

2.In module section find your project and in Dependancy tab add your library

Moien.Dev
  • 1,030
  • 2
  • 10
  • 18
  • 1
    actually your answer is not related to the question's context. Question is about adding ndk libraries which have a .so files. What you are telling is adding normal jar or aar based libraries. – Vivek Mishra Sep 19 '17 at 10:42