Android build: select which libraries to package from a shared native project

30 views
Skip to first unread message

Egor Yusov

unread,
May 11, 2020, 11:29:16 AM5/11/20
to android-ndk
My Android project consists of multiple applications, say App1 and App2 that all share the same project named Common. Common uses CMake to build few native components, including libApp1.so and libApp2.so. In my build.gradle file for App1 I have the following:

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



This generally works with one downside: dependency on Common makes both libApp1.so and libApp2.so packaged into both App1's and App2's apks. In reality I have 20+ native projects, so this becomes a real headache. What I want is to only take the required native libraries from the Common project, something like

implementation project(":Common", include: ['libApp1.so'])

Is there a way to achieve this in gradle?

Native CMake part is also used by build systems on other platforms, so it is highly undesirable to make significant Android-specific changes to it such as moving build commands for every native project into the corresponding Android build.gradle file.

Alex Cohn

unread,
Jun 7, 2020, 6:05:06 AM6/7/20
to android-ndk
You can tune android.packagingOptions {} to achieve this, like

android.packagingOptions {
    exclude("lib/*/libApp2.so")
}


BR,
Alex Cohn
Reply all
Reply to author
Forward
0 new messages