As per latest https://developer.android.com/jetpack/androidx/releases/compose-kotlin
I can see that we can use
Compose Compiler Version - 1.4.0
Compatible Kotlin Version - 1.8.0
However, after upgrade to compose 1.4.0 and kotlin 1.8.0, I got the error below
I got this error
Failed to resolve: androidx.compose.ui:ui-tooling:1.4.0
Failed to resolve: androidx.compose.ui:ui-test-manifest:1.4.0
Failed to resolve: androidx.compose.ui:ui:1.4.0
Failed to resolve: androidx.compose.ui:ui-tooling-preview:1.4.0
Failed to resolve: androidx.compose.ui:ui-test-junit4:1.4.0
Did I miss anything?
Yes, the libraries from the androidx.compose.ui package for compose version 1.4.0 have not been released yet.
The latest version for each of these libs is 1.4.0-alpha04. You can check the versions on this page
Compose compiler and the other compose dependencies have different releases.
Currently only compose.compiler has 1.4.0 stable.
To avoid this kind of problem you have different option:
Use the BOM
The Compose Bill of Materials (BOM) lets you manage all of your Compose library versions by specifying only the BOM’s version. The BOM itself has links to the stable versions of the different Compose libraries, in such a way that they work well together.
Going forward, Compose libraries will be versioned independently, which means version numbers will start to be incremented at their own pace.
Here you can find more info about BOM.
buildscript {
ext {
compose_compiler = '1.4.0' //compiler
}
//...
}
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
dependencies {
// Import the Compose BOM
implementation platform('androidx.compose:compose-bom:2022.12.00')
//....
}
Or use different version in your build script:
buildscript {
ext {
compose_compiler = '1.4.0' //compiler
compose_version = '1.3.x' //compose dependencies
compose_material3 = '1.0.1' //material3 release
}
//...
}
and then:
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
dependencies {
// compose releases (1.3.x)
implementation "androidx.compose.material:material:$compose_version"
//...
//material3
implementation "androidx.compose.material3:material3:$compose_material3"
}
Apparently, the compose version and composeCompiler version are different.
For now, the compose version is at 1.4.0-alpha04
buildscript {
ext {
compose_ui_version = '1.4.0-alpha04'
}
}
While the composeCompiler is now 1.4.0
android {
...
composeOptions {
kotlinCompilerExtensionVersion '1.4.0'
}
}
I copied project from GitHub and I want to modify it.
But I can't add LazyHorizontalGrid so I guess I need to update Jetpack Compose version or Gradle right?
What is proper way of doing that because if I do it with Project Structure as IDE suggest app crashes and I can't even build project.
I googled error and then next one and then next one and so on. But I think that it shouldn't be so hard to just update project.
LazyHorizontalGrid was added with 1.2.0 of the Compose Foundation dependency.
To update just change your build.gradle files.
In the root build.gradle file:
buildscript {
ext {
compose_version = '1.2.1'
}
//..
dependencies {
//...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
}
}
In your app/build.gradle:
android {
compileSdk 33
//...
composeOptions {
kotlinCompilerExtensionVersion 1.3.1
}
}
dependencies {
implementation "androidx.compose.foundation:foundation:$compose_version"
//...all the other compose dependencies
}
Check also the compatibility map for Compose Compiler Version/Kotlin Version.
Getting the following error when creating a new Compose Project in Android Studio and updating to the suggested compose version of 1.2.1:
Execution failed for task ':app:compileDebugKotlin'.
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
Required by:
project :app
I had to go to compose version 1.2.0, and kotlin version 1.7.0.
The best way to figure out what versions you will need, is to go to the compatibility guide.
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:
I've just started a new Jetpack Compose project using the "Empty Compose Activity" Android Studio (2020.3.1 Canary 14) template, but I'm getting the following warning in my build.gradle.kts (:app) file:
'kotlinCompilerVersion: String?' is deprecated.
The deprecation does not provide any information about what to use instead. Should I simply remove this option or do something else?
kotlinCompilerVersion can be safely removed.
Compose now uses the kotlin compiler defined in your buildscript.
buildscript {
ext.kotlin_version = '1.5.21'
//....
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
If you are using the plugins block (in settings.gradle or build.gradle)
pluginManagement {
//..
plugins {
id 'org.jetbrains.kotlin.android' version '1.5.21'
}
}
I seem to be having trouble with Preview in compose, the layout panel doesn't appear when I annotate a compose method with #preview. I assume I'm missing a dependency, but I've copied and pasted the code from here https://developer.android.com/jetpack/compose/setup. Any suggestions? (tried the usual clear cache, reopen project etc) :)
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.0.0-alpha10'
kotlinCompilerVersion '1.4.21'
}
}
dependencies {
implementation 'androidx.compose.ui:ui:1.0.0-alpha10'
// Tooling support (Previews, etc.)
implementation 'androidx.compose.ui:ui-tooling:1.0.0-alpha10'
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation 'androidx.compose.foundation:foundation:1.0.0-alpha10'
// Material Design
implementation 'androidx.compose.material:material:1.0.0-alpha10'
// Material design icons
implementation 'androidx.compose.material:material-icons-core:1.0.0-alpha10'
implementation 'androidx.compose.material:material-icons-extended:1.0.0-alpha10'
// Integration with observables
implementation 'androidx.compose.runtime:runtime-livedata:1.0.0-alpha10'
implementation 'androidx.compose.runtime:runtime-rxjava2:1.0.0-alpha10'
// UI Tests
androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.0.0-alpha10'
implementation 'com.google.android.material:material:1.2.1'
}
Here is my attempt at using preview (in AS it says Function "DefaultPreview" is never used)
import androidx.compose.ui.tooling.preview.Preview
.....
#Preview
#Composable
fun DefaultPreview() {
Text(text = "Hello!")
}
buildFeatures {
compose true
}
Write the above piece of code inside the Android block in the build.gradle file.
Your problem will then be solved.
For me it was some kind of mixture
Be sure you have latest Android Studio version
Within project/build.gradle be sure you have
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20'
}
Within app/build.gradle be sure you have
android {
composeOptions {
kotlinCompilerExtensionVersion'1.1.1'
}
buildFeatures {
compose true
}
}
dependencies {
implementation("androidx.compose.ui:ui:1.1.1")
// Tooling support (Previews, etc.)
debugImplementation "androidx.compose.ui:ui-tooling:1.1.1"
implementation "androidx.compose.ui:ui-tooling-preview:1.1.1"
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation("androidx.compose.foundation:foundation:1.1.1")
// Material Design
implementation("androidx.compose.material:material:1.1.1")
// Material design icons
implementation("androidx.compose.material:material-icons-core:1.1.1")
implementation("androidx.compose.material:material-icons-extended:1.1.1")
// Integration with observables
implementation("androidx.compose.runtime:runtime-livedata:1.1.1")
implementation("androidx.compose.runtime:runtime-rxjava2:1.1.1")
}
File -> Invalidate Ccaches and restart
Run project once
Very important:
check for correct #Preview import - should be:
import androidx.compose.ui.tooling.preview.Preview
Example:
#Composable
fun SimpleComposable() {
Text("Hello World")
}
#Preview
#Composable
fun ComposablePreview() {
SimpleComposable()
}
#Preview function should be without params.
I'm going to leave this up in case others run into the same issue as I did (it is user error, but I also think the documentation could be clearer).
There are two versions of Android Canary, beta and arctic fox (alpha). Make sure you are using arctic fox if you want to use the latest version of the compose libraries. I've found the compose library 'androidx.compose.ui:ui-tooling:1.0.0-alpha08' (and higher) doesn't work very well with the beta version of canary.
I think you can find something you want in configuration
For me, I missed one more dependency in my module's gradle
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
https://developer.android.com/jetpack/compose/tooling
Updating to the latest version of AS solved the error for me.
Try the latest version from here https://developer.android.com/studio/preview
The Jetpack Compose (rc01, rc02) has an issue with #Preview. You can solve it by adding the following code in your build.gradle file:
android {
...
}
configurations.all {
resolutionStrategy {
force("androidx.compose.ui:ui-tooling:1.0.0-beta09")
force("androidx.compose.ui:ui-tooling-data:1.0.0-beta09")
force("androidx.compose.ui:ui-tooling-preview:1.0.0-beta09")
}
}
dependencies {
...
}
Example: https://github.com/AlexZhukovich/ComposePlayground/blob/main/app/build.gradle
I had to add
debugImplementation 'androidx.customview:customview-poolingcontainer:1.0.0-rc01'
debugImplementation 'androidx.customview:customview:1.1.0'
Source
This is what worked for me add these dependencies if missed any
In the new AS compose runtime is missing and probably moved to something else and added UI tooling from the top when these were added studio started working with preview.
implementation("androidx.compose.runtime:runtime:1.2.0")
implementation("androidx.compose.ui:ui-tooling:1.2.0")
all together
implementation("androidx.activity:activity-compose:1.5.1")
implementation("androidx.compose.ui:ui:1.2.0")
implementation("androidx.compose.runtime:runtime:1.2.0")
implementation("androidx.compose.ui:ui-tooling-preview:1.2.0")
implementation("androidx.compose.ui:ui-tooling:1.2.0")
For me I just didn't have the following in my gradle file:
composeOptions {
kotlinCompilerExtensionVersion '1.0.3'
}
and
buildFeatures {
compose true
}
in project's build.gradle specify:
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
}
I had the same issue, and also had some compiling problems. My conclusion is that you need a good "variable versions" schema, for example is important use the same version for some dependencies, for example the Kotlin version.
I did something like this project: Jetpack Compose Navigation
where they using a global definition of version variables like this:
buildscript {
ext {
// Sdk and tools
compileSdkVersion = 33
minSdkVersion = 21
targetSdkVersion = 32
// App dependencies
appCompatVersion = '1.5.1'
activityComposeVersion = '1.6.0'
composeCompilerVersion = "1.3.0"
composeVersion = '1.2.1'
coreTestingVersion = '2.1.0'
espressoVersion = '3.4.0'
gradleVersion = '7.2.2'
kotlinVersion = '1.7.10'
ktlintVersion = '0.45.2'
ktxVersion = '1.9.0'
materialVersion = '1.6.1'
navigationComposeVersion = '2.5.2'
}
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:$gradleVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
}
}
And then use it in your app build.gradle too:
dependencies {
implementation project(path: ':libtoolscommon')
implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
implementation "androidx.core:core-ktx:$rootProject.ktxVersion"
implementation "com.google.android.material:material:$rootProject.materialVersion"
implementation 'androidx.preference:preference-ktx:1.2.0'
// Compose
implementation "androidx.compose.runtime:runtime:$rootProject.composeVersion"
implementation "androidx.compose.ui:ui:$rootProject.composeVersion"
implementation "androidx.compose.foundation:foundation:$rootProject.composeVersion"
implementation "androidx.compose.material:material:$rootProject.composeVersion"
implementation "androidx.compose.material:material-icons-extended:$rootProject.composeVersion"
implementation "androidx.activity:activity-compose:$rootProject.activityComposeVersion"
implementation "androidx.navigation:navigation-compose:$rootProject.navigationComposeVersion"
debugImplementation "androidx.compose.ui:ui-tooling:$rootProject.composeVersion"
// Testing dependencies
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$rootProject.espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.espressoVersion"
// Compose testing dependencies
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$rootProject.composeVersion"
debugImplementation "androidx.compose.ui:ui-test-manifest:$rootProject.composeVersion"
implementation "androidx.compose.material3:material3:1.0.0-beta03"
implementation "androidx.compose.material3:material3-window-size-class:1.0.0-beta03"
implementation 'androidx.window:window:1.1.0-alpha03'
---
}
And also try to have the last version of this libraries.
If you have a whole project in Kotlin, it should be like this:
implementation(libs.androidx.core.ktx)
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.androidx.compose.ui.tooling.preview)
debugImplementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.materialWindow)
implementation(libs.androidx.compose.material.iconsExtended)
implementation(libs.androidx.lifecycle.runtime)
implementation(libs.androidx.lifecycle.viewModelCompose)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.window)
Expect it to show in the 'Split' or 'Design' mode after a build. (Not right over code like it seems in the tutorial.)