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
.It should even be there already, or as transitive dependency of Android X, but Kotlin 2.2.10
should be used.
https://kotlinlang.org/docs/whatsnew14.html#dependency-on-the-standard-library-added-by-default
In fact, this does not need to be added explicitly ...
org.jetbrains.kotlin:kotlin-stdlib:2.2.10