diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 52d88d1c..5a8ba661 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -39,8 +39,8 @@ android { targetCompatibility = JavaVersion.VERSION_17 } - compilerOptions { - jvmTarget = JavaVersion.VERSION_17.toString() + kotlin { + jvmToolchain(17) } defaultConfig { @@ -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()) + } } } }