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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Egor Yusov
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.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/a242ffee-05b9-4111-a08f-735e50ae2ebf%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

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

Alex Cohn
On Monday, May 11, 2020 at 6:29:16 PM UTC+3, Egor Yusov wrote:
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.

You can tune android.packagingOptions {} to achieve this, like

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


BR,
Alex Cohn

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e08f6ae8-b5c3-49fe-9d2c-4e9d6707f308o%40googlegroups.com.