I m using packaging options to exclude some libs. Is it possible to have packaging options based on product flavor. For example -
android {
productFlavors {
flavorDimensions 'models'
S2 {
flavorDimension 'models'
minSdkVersion 22
....
}
S6 {
flavorDimension 'models'
minsdkversion 22
....
}
}
packagingOptions {
exclude 'lib/armeabi/libs2.so'
exclude 'lib/arm64-v8a/libs6.so
}
}
Now in above code, I want to exclude only 'lib/armeabi/libs2.so'
in apk generated for s6
flavor and want to exclude only 'lib/arm64-v8a/libs6.so'
in apk generated for s2
flavor
How can we achieve this.
This means you can generate different versions or variants of your app using a single codebase. Product flavors are a powerful feature of the Gradle plugin from Android Studio to create customised versions of products. They form part of what we call Build Variants.
Once the new project is created, by default it consists of two build types/variants - debug, release. Debug is the build type that is used when we run the application from the IDE directly onto a device. A release is the build type that requires you to sign the APK.
You use same core ingredients to make the base but will use different toppings for each one to have a different taste. Similarly, android apps can have the same base functionalities with changes to some of the features like styles, logo etc. This can be achieved using product flavours.
BuildConfig.FLAVOR gives you combined product flavor. So if you have only one flavor dimension: productFlavors { normal { } admin { } } Then you can just check it: if (BuildConfig. FLAVOR.
Based on @Dodolong solution:
packagingOptions {
...
gradle.startParameter.getTaskNames().each { task ->
if (task.contains('assemble')) {
if (task.contains('s2')) {
exclude 'lib/**/my_cool_lib1.so'
} else if (task.contains('s6')) {
exclude 'lib/**/my_cool_lib2.so'
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With