build: configure flavors for all modules

This commit is contained in:
Akash Yadav
2023-06-11 00:01:26 +05:30
parent a407842c55
commit 87cfa0040a
2 changed files with 40 additions and 30 deletions
-29
View File
@@ -14,8 +14,6 @@ plugins {
id("androidx.navigation.safeargs.kotlin")
}
val flavorsAbis = arrayOf("arm64-v8a", "armeabi-v7a")
android {
namespace = BuildConfig.packageName
@@ -26,33 +24,6 @@ android {
compileOptions { isCoreLibraryDesugaringEnabled = true }
flavorDimensions.add("default")
productFlavors {
flavorsAbis.forEach(this::create)
forEach {
defaultConfig.buildConfigField("String", "FLAVOR_${it.name.uppercase()}", "\"${it.name}\"")
}
}
splits {
abi {
reset()
isEnable = true
isUniversalApk = false
// TODO: Find a way to enable split APKs in product flavors. If this is possible, we can configure
// each flavor to include only a single ABI. For example, for the 'arm64-v8a' flavor,
// we can configure it to include only 'arm64-v8a' libraries. Size of APK can further be
// reduced by 10-15MB once this is achieved.
//
// See the contribution guidelines for more information.
@Suppress("ChromeOsAbiSupport")
include(*flavorsAbis)
}
}
downloadSigningKey()
// Keystore credentials
+40 -1
View File
@@ -19,6 +19,7 @@
import com.android.build.gradle.BaseExtension
import com.itsaky.androidide.plugins.AndroidIDEPlugin
import com.vanniktech.maven.publish.AndroidMultiVariantLibrary
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
import com.vanniktech.maven.publish.GradlePlugin
import com.vanniktech.maven.publish.JavaLibrary
@@ -45,6 +46,8 @@ buildscript {
}
}
val flavorsAbis = arrayOf("arm64-v8a", "armeabi-v7a")
fun Project.configureBaseExtension() {
extensions.findByType(BaseExtension::class)?.run {
compileSdkVersion(BuildConfig.compileSdk)
@@ -62,6 +65,42 @@ fun Project.configureBaseExtension() {
targetCompatibility = BuildConfig.javaVersion
}
// // ':common' module is configured to use product flavors as it uses the BuildConfig fields to
// // determine asset paths
// if (arrayOf(":app", ":common").contains(project.path)) {
// }
flavorDimensions("default")
productFlavors {
flavorsAbis.forEach(this::create)
forEach {
defaultConfig.buildConfigField("String",
"FLAVOR_${it.name.replace('-', '_').uppercase()}",
"\"${it.name}\"")
}
}
// configure split APKs for ':app' module only
if (this@configureBaseExtension == rootProject.findProject(":app")) {
splits {
abi {
reset()
isEnable = true
isUniversalApk = false
// TODO: Find a way to enable split APKs in product flavors. If this is possible, we can configure
// each flavor to include only a single ABI. For example, for the 'arm64-v8a' flavor,
// we can configure it to generate APK only for 'arm64-v8a'.
//
// See the contribution guidelines for more information.
@Suppress("ChromeOsAbiSupport")
include(*flavorsAbis)
}
}
}
buildTypes.getByName("debug") { isMinifyEnabled = false }
buildTypes.getByName("release") {
isMinifyEnabled = true
@@ -126,7 +165,7 @@ subprojects {
signAllPublications()
if (plugins.hasPlugin("com.android.library")) {
configure(AndroidSingleVariantLibrary())
configure(AndroidMultiVariantLibrary())
} else if (plugins.hasPlugin("java-gradle-plugin")) {
configure(GradlePlugin(javadocJar = JavadocJar.Javadoc()))
} else if (plugins.hasPlugin("java-library")) {