简体   繁体   中英

Imported library doesn't build in Android Studio 2.2

I try to add a imported library to my project, and link it to another Library.

Here is some part of my code from CMakeLists.txt:

add_library(native-lib SHARED ${sources})

add_library(imported-lib SHARED IMPORTED)

set_target_properties(imported-lib PROPERTIES IMPORTED_LOCATION   ${CMAKE_CURRENT_LIST_DIR}/PathToLibs/${ANDROID_ABI}/imported-lib.so)

In my native-lib, I create an object of a Class which is placed in imported-lib but the app starts crash. (if I debug or run the app then make project works fine)

In the Gradle Console i get an Info: [org.gradle.api.Task] externalNativeBuildDebug: not building target imported-lib because there was no build command for it

How can I build it?

The shared lib currently need to packed into apk manually, one way is to route jniLibs to your shared lib directory. Hope later version could pack it automatically. One example is here, https://github.com/googlesamples/android-ndk/tree/master/hello-libs , it imports one shared lib, one static lib; shared lib is packed to APK with script in app/build.gradle:jniLibs.srcDirs = ['../distribution/gperf/lib']

As a workaround for me is so in the build.gradle. The 'make' must be in PATH.

externalNativeBuild {
    cmake {
    ...
        arguments "-GAndroid Gradle - Unix Makefiles",
                  "-DCMAKE_MAKE_PROGRAM=make"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM