'Problems with android Compose
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.
Solution 1:[1]
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.
Solution 2:[2]
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"
}
Solution 3:[3]
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"}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ????? ??? |
Solution 2 | Vasudev Vyas |
Solution 3 | Mohsents |