Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] support packing IMPORTED SHARED library with CMake #928

Closed
alexcohn opened this issue Mar 9, 2019 · 1 comment
Closed

[FR] support packing IMPORTED SHARED library with CMake #928

alexcohn opened this issue Mar 9, 2019 · 1 comment
Assignees

Comments

@alexcohn
Copy link

alexcohn commented Mar 9, 2019

This Feature Request should be part of the NDK integration for CMake, and is based on a common scenario, see How can I integrate OpenCV 4.0 into a pure C++ Android NDK project?.

When we use an IMPORTED SHARED library in CMake build, it is not packed into the APK. This behaviour is not consistent with what happens when we use ndk-build instead of CMake.

An official sample suggest a way to do this in Gradle:

sourceSets {
    main {
        // let gradle pack the shared library into apk
        jniLibs.srcDirs = ['../distribution/gperf/lib']
    }
}

The latter solution is less attractive to me because it involves sharing some knowledge (e.g. paths to native dependencies) between CMake and Gradle. It's preferable IMO to handle this entirely in CMake and copy the file to CMAKE_LIBRARY_OUTPUT_DIRECTORY:

get_target_property(__src opencv_java IMPORTED_LOCATION_RELEASE )
add_custom_command(TARGET app POST_BUILD COMMAND
    ${CMAKE_COMMAND} -E copy ${__src} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)

At the very least, this issue should be properly documented.

It would help a lot to add some helper macro to the CMake toolchain file, which would take care of declaring an imported shared library and packing it into the APK, so that CMake is on par with ndk-build.

I believe it's possible to teach the Gradle plugin pack such libraries without changing the user-side scripts, but maybe today this would cause more confusion, because this would be a braking change for the behaviour that has been there for quite a while.

@DanAlbert
Copy link
Member

DanAlbert commented Apr 13, 2020

I'm pretty sure I fixed this as part of #916. AGP 4.0 shouldn't have this problem. It's definitely fixed for the case of a library imported via a config package. I'll wait to make sure your project agrees before fixing the docs :)

You shouldn't need to do any sort of cofig with 4.0. Just depending on the library should get it added to the APK.

@DanAlbert DanAlbert self-assigned this Apr 13, 2020
@DanAlbert DanAlbert added this to the unscheduled docs milestone Apr 13, 2020
@alexcohn alexcohn changed the title [FR] support packing IMPORTED SHAREDlibrary with CMake [FR] support packing IMPORTED SHARED library with CMake Apr 14, 2020
@alexcohn alexcohn closed this as completed Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants