Created
February 22, 2026 12:19
-
-
Save Zekfad/ae8f4fc24db32412368a3595cae31b3c to your computer and use it in GitHub Desktop.
Flutter (Android): override minimum compile SDK version for every project and force JDK/Java version for every subproject
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ... | |
| // override minimum compile sdk version for every project | |
| // and override JDK version for every project | |
| var flutterCompileSdkVersion = 0 | |
| subprojects { | |
| afterEvaluate { | |
| plugins.withType<com.flutter.gradle.FlutterPlugin> { | |
| configure<com.flutter.gradle.FlutterExtension> { | |
| flutterCompileSdkVersion = compileSdkVersion | |
| } | |
| } | |
| plugins.withType<com.android.build.gradle.BasePlugin> { | |
| configure<com.android.build.gradle.BaseExtension> { | |
| val current = (compileSdkVersion ?: "android-1").substring(8).toInt() | |
| if (current < flutterCompileSdkVersion) { | |
| compileSdkVersion(flutterCompileSdkVersion) | |
| } | |
| compileOptions { | |
| sourceCompatibility = JavaVersion.VERSION_21 | |
| targetCompatibility = JavaVersion.VERSION_21 | |
| } | |
| } | |
| } | |
| plugins.withType<org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin> { | |
| configure<org.jetbrains.kotlin.gradle.dsl.KotlinBaseExtension> { | |
| jvmToolchain(21) | |
| } | |
| } | |
| plugins.withType<org.gradle.api.plugins.JavaBasePlugin> { | |
| configure<org.gradle.api.plugins.JavaPluginExtension> { | |
| toolchain { | |
| languageVersion = JavaLanguageVersion.of(21) | |
| } | |
| } | |
| } | |
| tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask<org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions>>().configureEach { | |
| compilerOptions { | |
| jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21 | |
| } | |
| } | |
| } | |
| } | |
| // ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment