Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ android {
targetCompatibility = JavaVersion.VERSION_17
}

compilerOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
kotlin {
jvmToolchain(17)
}

defaultConfig {
Expand Down Expand Up @@ -129,17 +129,25 @@ android {
}

val abiCodes = mapOf("x86_64" to 1, "armeabi-v7a" to 2, "arm64-v8a" to 3)
androidComponents {
onVariants { variant ->
variant.outputs.forEach { output ->
val abiFilter = output.filters.find {
it.filterType == com.android.build.api.variant.VariantOutputConfiguration.FilterType.ABI
}
val abiVersionCode = abiFilter?.identifier?.let { abiCodes[it] }

android.applicationVariants.configureEach {
val variant = this
variant.outputs.forEach { output ->
val abiVersionCode = abiCodes[output.filters.find { it.filterType == ABI }?.identifier]
if (abiVersionCode != null) {
// Create a version code within Android limits (max 2100000000)
// Use: (YYMMDDHH % 100000) * 100 + ABI to stay well under limits
val baseBuildNumber = flutterVersionCode.toLong()
val compressedCode = (baseBuildNumber % 100000) * 100 + abiVersionCode
(output as ApkVariantOutputImpl).versionCodeOverride = compressedCode.toInt()
if (abiVersionCode != null) {
// Create a version code within Android limits (max 2100000000)
// Use: (YYMMDDHH % 100000) * 100 + ABI to stay well under limits
val baseBuildNumber = requireNotNull(flutterVersionCode.toLongOrNull()) {
"Invalid flutter.versionCode='$flutterVersionCode' in local.properties; must be a number."
}
val compressedCode = (baseBuildNumber % 100000) * 100 + abiVersionCode
val maxPlayVersionCode = 2_100_000_000L
val safeVersionCode = compressedCode.coerceIn(1L, maxPlayVersionCode)
output.versionCode.set(safeVersionCode.toInt())
}
}
}
}
Expand Down
Loading