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:
Related
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.
I have an Android Studio project that works fine when I'm using Kotlin version 1.6.21 and compose version 1.2.0-rc01. The problem arises when I want to update both dependencies to the latest versions, which are 1.7.10 for Kotlin and 1.3.0-alpha01 for compose. The error that I get is:
Could not resolve all files for configuration ':app:kotlin-extension'.
Could not find androidx.compose.compiler:compiler:1.3.0-alpha01.
Searched in the following locations:
https://dl.google.com/dl/android/maven2/androidx/compose/compiler/compiler/1.3.0-alpha01/compiler-1.3.0-alpha01.pom
https://repo.maven.apache.org/maven2/androidx/compose/compiler/compiler/1.3.0-alpha01/compiler-1.3.0-alpha01.pom
Required by:
project :app
Any help?
Edit:
Now I'm using these versions:
kotlinCompilerExtensionVersion '1.7.10'
implementation "androidx.compose.ui:ui:1.3.0-alpha01"
implementation "androidx.compose.material:material:1.3.0-alpha01"
implementation "androidx.compose.compiler:compiler:1.2.0"
Compose compiler and the other compose dependencies have different releases.
Currently the latest version of compose.compiler is 1.3.1.
You easily use different versions in your build.gradle script:
buildscript {
ext {
compose_compiler = '1.3.1'. //compiler
compose_version = '1.2.0'. //stable compose dependencies
compose_alpha = '1.3.0-alpha01' //alpha releases
}
//...
}
And then:
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
dependencies {
//stable releases
implementation "androidx.compose.material:material:$compose_version"
//alpha releases
implementation "androidx.compose.ui:ui:$compose_alpha"
implementation "androidx.compose.material3:material3:$compose_alpha"
}
An alternate Compose compiler version can be defined with composeOptions:
android {
composeOptions {
kotlinCompilerExtensionVersion "1.2.0"
}
}
There's no need to add it as an implementation, which it definitely isn't.
runtimeOnly might eventually work, but it won't make it into the package.
There is a compatibility map for "Compose Compiler Version" compatible with "Compatible Kotlin Version" it can be found here:
so if you want to update to today's latest compose you specify:
...
composeOptions {
kotlinCompilerExtensionVersion "1.3.0"
}
...
and then in the map you find the compatible kotlin version which is 1.7.10
and set that in the other gradle file:
plugins {
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
...
}
I am using compose_version is 1.3.0-beta01 which is working fine for me. You may use like below:
Step1: Project build.gadle is look like below:
build script {
ext {
compose_version = '1.3.0-beta01'
}
}
plugins {
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
Step2: module build.gadle looks like
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
Today I updated gradle and kotlin dependencies in android studio.
The new versions are these:
kotlin_version = "1.5.10"
...
jacoco {
toolVersion = "0.8.6"
}
...
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
The test coverage report task fails with the following error:
2021-05-27T16:57:49.150+0200 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':consumerkit:testDebugUnitTestCoverage'.
2021-05-27T16:57:49.304+0200 [DEBUG] [org.codehaus.groovy.vmplugin.VMPluginFactory] Trying to create VM plugin `org.codehaus.groovy.vmplugin.v9.Java9` by checking `java.lang.Module`, but failed:
java.lang.ClassNotFoundException: java.lang.Module
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.groovy.vmplugin.VMPluginFactory.lambda$createPlugin$0(VMPluginFactory.java:61)
at java.security.AccessController.doPrivileged(Native Method)
For Kotlin 1.5 you should use JaCoCo 0.8.7 instead of 0.8.6 - see https://github.com/jacoco/jacoco/pull/1164 and the full changelog at https://www.jacoco.org/jacoco/trunk/doc/changes.html
Example snippet:
// build.gradle or build.gradle.kts
jacoco {
toolVersion = "0.8.7"
}
I already had the
jacoco {
toolVersion = "0.8.7"
}
configured but it was not working anyway, what fixed the problem was to follow this comment here
In your module build.gradle switch back to:
android {
//....
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
don't worry, it won't break anything if you were not using Java 11 language features yet, AGP 7 is still compatible with JDK 8 as target.
Then you need to force AGP to use the 0.8.7 version and not the default 0.8.3 one. In your allprojects block in the root build.gradle file, add this:
allprojects {
//... other things
// workaround to fix an auto-import of a lower Jacoco version
resolutionStrategy {
eachDependency { details ->
if ('org.jacoco' == details.requested.group) {
details.useVersion "0.8.7"
}
}
}
}
and now it should work using:
AGP 7.0.X
Kotlin 1.5.X
JDK 11 (embedded with AS)
Simply doing
jacoco {
toolVersion = "0.8.7"
}
was not enough for me. I also had to override the version that Android was using so that the androidJacocoAnt dependency also uses 0.8.7. (./gradlew app:dependencies) Simply add this to your gradle too
android.jacoco.version = "0.8.7"
It's quite old thread, but these solutions did not solve my problems completely in Android project (actually written in Java - not in Kotlin), so I will add my solutions here. Maybe someone will find it helpful.
Except of updating jacoco toolVersion to 0.8.7, I also had to update execution data in my jacoco config as follows:
project.afterEvaluate {
tasks.create(name: "${unitTestTask}Coverage", type: JacocoReport,
dependsOn: [
"$unitTestTask",
":sdk:testDebugUnitTest",
":sdk:connectedCheck"
]) {
/* all jacoco custom configuration goes here... */
executionData(fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec",
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
"outputs/code_coverage/debugAndroidTest/connected/*coverage.ec"
]))
}
}
in this configuration I had to add the following line:
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec"
which wasn't there before because file with generated report used by sonar was generated in the new location. Report is generated with gradle task testDebugUnitTestCoverage. After all of that, I'm able to generate test coverage report including connected/instrumentation Android tests and regular unit tests in java via sonar.
I am getting the following error when trying to build the project.
The only difference is the gradle script is in Kotlin DSL.
could not resolve plugin artifact 'io.fabric:io.fabric.gradle.plugin:1.25.4')
Below is my entire build.gradle.kts file
https://gist.github.com/nksaroj/483f3f07df8e04c72040ea4c055459d6
Or https://github.com/nksaroj/xDemo is the full project.
Use applying plugin in build block:
https://docs.gradle.org/current/userguide/plugins.html#sec:applying_plugins_buildscript
For io.fabric:
buildscript {
repositories {
maven("https://maven.fabric.io/public")
}
dependencies {
classpath("io.fabric.tools:gradle:1.25.4")
}
}