I am trying to work through a tutorial on android compose. It works well while I use:kotlin-gradle-plugin:1.5.31, but the android studio has updated to :kotlin-gradle-plugin:1.6.10, and when I try running the program again it doesn't compile. I don't understand what the problem is. but even in the original run with the old version, I get the following message:
w: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
when I try the new version it tells me that I must migrate the code, but when I do this I get the following message:
e: This version (1.0.5) of the Compose Compiler requires Kotlin version 1.5.31 but you appear to be using Kotlin version 1.6.10 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
Task :app:mergeExtDexDebug
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
Compilation error. See log for more details
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 10s
25 actionable tasks: 23 executed, 2 up-to-date
and you can't migrate back even if you want to.
I don't know what to do with this or how to proceed forward.
I managed to find out that the right compos version for kotlin 1.6.10 is 1.2.0-alpha01, but I still get the message that this is not a stable version and should not be production use. But at least my program runs again.
Finally, Figure out and fix the issue to run compose version
Currently Stable version 1.1.0
So here is my code for build.gradle(Project:app)
buildscript {
ext {
compose_version = '1.1.0'
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.dreammeanings"
minSdk 21
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'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
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.4.1'
implementation 'androidx.activity:activity-compose:1.4.0'
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"
}
In my case i specified kotlinCompilerExtensionVersion for composeOptions in build.gradle of the app module and error fixed:
build.gradle(app)
android {
composeOptions { kotlinCompilerExtensionVersion = "your compose version"}
}
I think your problem is with the version of Compose and Kotlin.
A few days ago, I encountered a similar error, and after updating the Kotlin and Compose versions, my problem was fixed.
First of all change composeOptions:
composeOptions {
kotlinCompilerExtensionVersion compose_version
//kotlinCompilerVersion '1.5.31' the old version
kotlinCompilerVersion '1.6.21'
}
then update all your dependencies versions
dependencies {
implementation "androidx.compose.ui:ui-tooling:$compose_version"
.
.
.
}
then add this classpaths to gradle dependencies
dependencies {
//the older version of kotlin
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
.
.
.
}
At the end, i think this is an version compatibility issue between Kotlin and compose libraries.
You just need to update your dependencies.
Note : the $compose_version that i used in the dependencies is an variable in buildscript
buildscript {
ext {
kotlin_version = "1.6.21"
//compose_version = '1.0.5'
compose_version = '1.2.0-rc01'
}
.
.
.
}
I hope it helps you to solve your problem.
Related
I am trying to add this ColorPicker to my Android project.
I imported this library into my Java class:
import petrov.kristiyan.colorpicker.ColorPicker;
When I add it to Gradle and sync, I don't get any error.
But when I build the project, I get this error:
Task 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 petrov.kristiyan:colorpicker-library:1.1.10.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/petrov/kristiyan/colorpicker-library/1.1.10/colorpicker-library-1.1.10.pom
- https://repo.maven.apache.org/maven2/petrov/kristiyan/colorpicker-library/1.1.10/colorpicker-library-1.1.10.pom
Required by:
project :app
Gradle Project file:
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
}
Gradle App file:
plugins {
id 'com.android.application'
}
android {
namespace 'com.example.appname'
compileSdk 33
defaultConfig {
applicationId "com.example.appname"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'petrov.kristiyan:colorpicker-library:1.1.10'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
I have Android Studio version 2021.3.1 Patch 1 installed.
I followed the steps mentioned in this post, but it didn't work.
I am facing the same issue with this ColorPicker too.
Does anyone have any other solution to this problem?
I tried pulling the library and had same results as yours. Looking at these 3 search results from the maven repository
Search Result 1
Search Result 2
Search Result 3
Looks like the repository hasn't been updated for years, have you considered looking for another color-picker library?, I'd recommend this one that I use.
Go Daddy Color Picker
Not sure though if the developers have an xml version of this, as this is targeted to Compose usage, but you can integrate composables to xml, and this picker returns an object that holds 4 properties of a Color, hue, saturation, alpha and value that you can use.
It looks like the library is old and wasn't migrated to the Maven Central repository, since JCenter was deprecated.
But you can use it from Jitpack repository:
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency to your app build.gradle:
dependencies {
implementation 'com.github.kristiyanP:colorpicker:v1.1.10'
}
Enjoy!
Hello I tried to run Kotlin file on Android Studio (version 4.1) and I got an error:
Kotlin library {0} was compiled with a newer Kotlin compiler and can't be read. Please update Kotlin plugin.
Even I got this error I'm able to run kotlin files but Ide don't gives me tips when I use kotlin functions and methods are marked by red colour. Kotlin version in gradle is 1.6.0, if I'm return to older version I can see tips about method names and red colour is not showed.
Gradle build(app):
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.kotlin_udemy4"
minSdkVersion 26
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Gradle build:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.6.0"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Does anyon know how to resolve that issue ?
Besides Kotlin version 1.6.21 ...
That version of Android Studio appears rather outdated; eg. the current version "Chipmunk" uses:
com.android.tools.build:gradle:7.2.1
jcenter() should be replaced with mavenCentral().
And also, use JavaVersion.VERSION_11.
I have similar problem. To solve this, I do the following things:
I try to Rebuild the project, then this error log appear:
The minCompileSdk (32) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-31).
Dependency: androidx.appcompat:appcompat-resources:1.5.0.
AAR metadata file: C:\Users..........
Lower androidx.appcompat:appcompat version to 1.4.0, and then sync gradle. That's it.
Maybe you can try this way.
Next to isssue popup i selected "Details" link and there was information about expected version. Probably because I'm using older Android studio I got the problem. I updated Kotlin in gradle build to: 1.4.32 according to message.
I am facing an error:
Some Kotlin libraries attached to this project were read by a newer Kotlin compiler and can't be read. Please update Kotlin Plugin
I just created an application and started facing this error:
The Kotlin plugin shows the following:
I tried to change ext.kotlin_version:
My build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.32"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My build.gradle(app):
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 31
buildToolsVersion '30.0.1'
defaultConfig {
applicationId "com.yousufjamil.myj"
minSdkVersion 16
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
I would appreciate any help. Thank You!
You need to update almost everything, I believe.
currently for Gradle we have
com.android.tools.build:gradle:7.2.1
coming to Kotlin, the current version is 1.6.21
repository jcenter() is deprecated and has been replaced by mavenCentral()
If you try to use jcenter() it will give a warning
JCenter Maven repository is no longer receiving updates: newer library versions may be available elsewhere
Also, check if there are any updates available for Android Studio.
Earlier I had the same error on Android Studio. If by changing the kotlin-version and gradle-version in the build.gradle file does not fixes the error. It might be because you have an older version and need to update the Android Studio [File -> Settings -> Appearance & Behavior -> System Settings -> Updates -> ' then Change to the latest stable version']. Later during the installation process, you would see the option to upgrade the gradle where you can choose the latest version. It worked for me. Hope it helps!
1- update the android studio by clicking the tab named help and then click "check for update" and then let the android studio be updated.
2 - restart the android studio if the error is resolved then it's well and good if not, then click on the tab "New", click on "New project" and then select project, and check the box highlighted here in the below picture.
click here to see the image
this worked for me
update android studio to the lastest version
only need to del these
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
I just run RC1 version of artic fox, unfortunately I'm always getting the same error when I try to run empty compose activity project and that's the error.
I have no idea where 1.0.0-rc01 come from, when everything is changed to rc02
> Task :app:compileDebugKotlin FAILED
w: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
e: This version (1.0.0-rc01) of the Compose Compiler requires Kotlin version 1.5.10 but you appear to be using Kotlin version 1.5.21 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
Execution failed for task :app:compileDebugKotlin
It's a fresh copy of RC1 Arctic Fox, just did a few updates. What am I missing here?
Here is my build.gradle
buildscript {
ext {
compose_version = '1.0.0-rc02'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0-rc01"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
:app
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
buildToolsVersion "31.0.0"
defaultConfig {
applicationId "com.example.testoandroid1"
minSdk 21
targetSdk 31
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'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
// Material design icons
implementation 'androidx.compose.material:material-icons-core:1.0.0-rc02'
implementation 'androidx.compose.material:material-icons-extended:1.0.0-rc02'
implementation "androidx.compose.material:material:$compose_version"
// Tooling support (Previews, etc.)
implementation 'androidx.compose.ui:ui-tooling:1.0.0-rc02'
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation 'androidx.compose.foundation:foundation:1.0.0-rc02'
// Integration with ViewModels
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.0-rc02'
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"
// Integration with observables
implementation 'androidx.compose.runtime:runtime-livedata:1.0.0-rc02'
implementation 'androidx.compose.runtime:runtime-rxjava2:1.0.0-rc02'
}
You had to use 1.5.10 kotlin with compose, it's the latest version supported right now
I haven't found specific restrictions in the docs, but on the release page(https://developer.android.com/jetpack/androidx/releases/compose-compiler#declaring_dependencies) they suggest using 1.5.10.
If you try to build the app using 1.5.21, you'll get an error:
e: This version (1.0.0-rc02) of the Compose Compiler requires Kotlin version 1.5.10 but you appear to be using Kotlin version 1.5.21 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
I've tried building it with suppressKotlinVersionCompatibilityCheck, in my case it fails with java.lang.InstantiationError: org.jetbrains.kotlin.ir.util.TypeTranslator.
I suggest it's has something to do with new kotlin backend which gets many updates in recent versions, and looks like compose depends on it much.
Change the second dependency in your project level build.gradle file to
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
Change your Kotlin version of the project to 1.5.21 to 1.5.10. Because Jetpack compose 1.0.0-rc1 or rc2 version only works with Kotlin Version 1.5.10.
Previously:
1.5.21
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
Make it now:
1.5.10
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
Compose supports Kotlin 1.5.21 starting from 1.0.1.
Have a good day everyone. I am starting my studies in Kotlin using Android Studio in its version 4.2.2. I have created a project from 0 using the IDE itself and I get the error:
Execution failed for task ':app:mergeLibDexDebug'
Failed to calculate the value of task ':app:mergeLibDexDebug' property
'numberOfBuckets'.
Expected minSdkVersion >= 21 but found 1
I was looking in other publications that spoke of compilation problems mainly due to incompatibilities in the dependencies included in the project, but none spoke exactly about the error that I am presenting...
The gradle module has the default code when creating the application which is the following:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.nueva"
minSdkVersion 28
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
The gradle project also has the default configuration that it brings when the application is created:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.20"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
// jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I don't have any additional implementation either in MainActivity.kt or another project file. If anyone has been through this error and fixed it please I would really appreciate if you would share with me how to eliminate this error. Maybe the solution is simple, but as I said before I am new to the world of Kotlin and I would like very much in the future to be able to be involved in the world of developing applications for smartphones. Without further ado, thank you very much in advance to anyone who can help
Can you make sure test on a Device >= API Level 21 ? Also check from Settings for New Projects to be selected Android 11.0 (R) or Android 9.0 Pie (check also these versions are installed in sdk manager)