After upgrading my Flutter project's Gradle and Android Gradle Plugin (AGP) to the latest versions, the build.gradle.kts
file for my app module was updated to the following:
plugins {
id("com.android.application")
id("kotlin-android")
id("dev.flutter.flutter-gradle-plugin")
}
android {
namespace = "xx.xxxxx.xx"
compileSdk = 36
ndkVersion = "29.0.13846066"
compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
}
}
defaultConfig {
applicationId = "xx.xxxxx.xx"
minSdk = 30
targetSdk = 34
versionCode = flutter.versionCode
versionName = flutter.versionName
}
buildTypes {
release {
signingConfig = signingConfigs.getByName("debug")
}
}
buildToolsVersion = "36.0.0"
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk11:2.0.20")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
implementation("androidx.core:core:1.13.1")
}
flutter {
source = "../.."
}
However, when I try to build the project, I encounter the following error, even after testing different versions of the Kotlin standard library:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk11:2.2.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk11/2.2.0/kotlin-stdlib-jdk11-2.2.0.pom
- https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk11/2.2.0/kotlin-stdlib-jdk11-2.2.0.pom
- https://storage.googleapis.com/download.flutter.io/org/jetbrains/kotlin/kotlin-stdlib-jdk11/2.2.0/kotlin-stdlib-jdk11-2.2.0.pom
Required by:
project :app
Additional Context:
settings.gradle
file includes the Kotlin plugin version 2.2.10
.2.0.20
and 1.9.24
, but the error persists, and it seems to be looking for 2.2.0
.Because I was attempting to use the kotlin-stdlib-jdk11
library, version 2.0.20, which does not exist, my build was failing. As it turns out, the most recent stable version of the Kotlin libraries is 1.9.24, and the 2.x versions are not yet publicly accessible. The problem was fixed as soon as I updated my dependencies to the appropriate versions.
This is how my fixed dependencies block appears:
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.24")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
implementation("androidx.core:core-ktx:1.13.1")
}