Expressing runtime dependencies in INTERFACE_LINK_LIBRARIES


I don’t know how this is specific to Android development, but here it is.

For Android Studio to properly pack in an .apk file the runtime dependencies (the .so libraries) of an exported target (being a shared library or an application), I’ve discovered that they must be listed in the target INTERFACE_LINK_LIBRARIES (direct or transitively inherited). Otherwise, they’re not added to the final APK, resulting in a crash at application startup. I know for sure that Android Studio (probably the Android Gradle Plugin underneath) doesn’t rely on file(GET_RUNTIME_DEPENDENCIES), or TARGET_RUNTIME_DLLS genex to get/pack the runtime dependencies (Google Issue Tracker). So, I was just wondering how is it correct/nonsense to express a target runtime dependencies as INTERFACE_LINK_LIBRARIES?

Doing so has consequences. In order to populate a target INTERFACE_LINK_LIBRARIES, the dependencies must be added with target_link_libraries(... PUBLIC ...), even for e.g. implementation-only dependencies. Otherwise, they’ll be added to the target IMPORTED_LINK_DEPENDENT_LIBRARIES property and won’t be part of the APK. For a shared library, declaring all its dependencies as PUBLIC will then requires that all its targets are exported, thus requiring that the exported config file package has find_dependencies() for all the dependencies (e.g. OpenCV modules built as separate .so files), although this isn’t strictly necessary from the build point of view.

Is this an Android-specific workaround to make Android Studio happy or a generic and comprehensive approach?