I create an project based the wizard Empty Compose Activity of Android Studio Chipmunk | 2021.2.1 Patch 1. It can be compiled, and it works well.
I get the following running error after I upgrade compose_version from compose_version = '1.1.0-beta01'
to 1.2.1
.
Could not resolve all files for configuration ':app:kotlin-extension'.
> Could not find androidx.compose.compiler:compiler:1.2.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/androidx/compose/compiler/compiler/1.2.1/compiler-1.2.1.pom
- https://repo.maven.apache.org/maven2/androidx/compose/compiler/compiler/1.2.1/compiler-1.2.1.pom
But the app can run well when I remove kotlinCompilerExtensionVersion compose_version
in build.gradle (Module), why?
build.gradle (Project)
buildscript {
ext {
compose_version = '1.1.0-beta01' //I will upgrade it to 1.2.1
}
}
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}
build.gradle (Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.myapplication"
minSdk 25
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
composeOptions {
kotlinCompilerExtensionVersion compose_version //OK after I removed it
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
packagingOptions {
resources {
excludes = '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
CodePudding user response:
The problem is that there is no Compose Compiler 1.2.1
version. Currently, Compose Compiler
follows a different release schedule than other Compose libraries
.
Here is the compatibility map and the available versions of Compose Compiler
to use together with Kotlin
.
In case you're wondering about using different versions between Compose Compiler
and the other Compose libraries
, it's totally ok to do that, and that's what you should do to have access to the latest versions of them.
You can configure your gradle as follows:
Project module
buildscript {
ext {
kotlinVer = '1.7.10'
composeCompilerVer = '1.3.1' // should be compatible with kotlin version
composeVer = '1.2.1'
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version "$kotlinVer" apply false
// ...
}
App module
// ...
android {
// ...
composeOptions {
kotlinCompilerExtensionVersion composeCompilerVer
}
// ...
}
dependencies {
implementation "androidx.compose.ui:ui:$composeVer"
implementation "androidx.compose.ui:ui-tooling-preview:$composeVer"
// ...
}
CodePudding user response:
The version androidx.compose.compiler:compiler:1.2.1
doesn't exist.
You can check it in the google maven repo
You can in any case use the stable version of the module compiler 1.3.0
and all the other compose dependencies at 1.2.1:
buildscript {
ext {
compose_compiler = '1.3.0'
compose_version = '1.2.1'
}
//...
}
and then:
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
dependencies {
// stable 1.2.1 releases
implementation "androidx.compose.material:material:$compose_version"
//...
}
As described in the documentation the compiler 1.3.0 requires kotlin 1.7.10: