When I'am trying to run the app I getting the following error
"java.lang.IllegalStateException: Function not found androidx.compose.internal.restartableFunctionInstance"
and the following warning:
C:\Users\amr\.gradle\caches\transforms-2\files-2.1\29795ea219aedbe5401209deaa0aa414\jetified-kotlin-stdlib-jdk7-1.3.60-eap-25.jar: Runtime JAR file has version 1.3 which is older than required for API version 1.4
Here is my code in the activity:
class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle ? ) {
super.onCreate(savedInstanceState)
setContent {
Text("Hello World")
}
}
}
I am using android studio 4.2 canary 2
Here is the full build.gradle file"
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myfirstCompse"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
compose true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
composeOptions {
kotlinCompilerExtensionVersion "0.1.0-dev09"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.ui:ui-framework:0.1.0-dev09'
implementation 'androidx.ui:ui-tooling:0.1.0-dev09'
implementation 'androidx.ui:ui-layout:0.1.0-dev09'
implementation 'androidx.ui:ui-material:0.1.0-dev09'
}
Update: when I change the dependency version to dev09, and added compileOptions block as the documentation suggests
composeOptions {
kotlinCompilerExtensionVersion "0.1.0-dev09"
}
it produced the following error:
e: java.util.NoSuchElementException: Collection contains no element matching the predicate.
Add kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424" to your composeOptions closure:
composeOptions {
kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
kotlinCompilerExtensionVersion "0.1.0-dev09"
}
You definitely need this; I am uncertain if it will clear up this specific error.
You may wish to check the version of Kotlin that you are using in your project-level build.gradle file. 1.3.70 is a known safe version (it matches the compiler plugin version from my code snippet).
Related
I want to update dependencies to latest version of Jetpack Compose. I tried to change version texts in gradle files but build error. Also I can't find what is the latest version of Jetpack Compose.
build.gradle (Project)
buildscript {
ext {
compose_version = '1.2.0'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}
build.gradle (Module:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.android'
compileSdk 33
defaultConfig {
applicationId "com.example.android"
minSdk 24
targetSdk 33
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 '1.2.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.0.0-alpha11'
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"
}
I tried and searched on internet for two days but always build error.I'm very noob at this jobs, so it didn't work.
Jetpack compose has switched to using a bill of materials (BOM) to combine compatible library versions.
Check out the documentation:
dependencies {
// Import the Compose BOM
implementation platform('androidx.compose:compose-bom:2023.01.00')
// Import other Compose libraries without version numbers
implementation 'androidx.compose.foundation:foundation'
}
You can find the latest BOM version here.
If you are still getting build errors then you most likely need to update your kotlin plugin version.
After updating Compose to be able to use Modifier.blur, I got errors which were resolved after updating other dependencies. But now two animations I use (AnimateDpAsState and AnimatedVisibility) does not work.
I get the following error while building in release mode and it still builds successfully. No errors on debug mode.
lifecycle-runtime-ktx_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
I am pretty sure the problem lies in the gradle files so please take a look.
module build.grade
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.dagger.hilt.android'
id "org.jetbrains.kotlin.kapt"
}
android {
namespace 'com.example.app'
compileSdk 33
defaultConfig {
applicationId "com.example.app"
minSdk 21
targetSdk 33
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 '1.4.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
// Compose
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.0-alpha05"
implementation "androidx.navigation:navigation-compose:2.6.0-alpha04"
implementation "androidx.compose.material:material-icons-extended:1.3.1"
implementation "androidx.hilt:hilt-navigation-compose:1.1.0-alpha01"
//Dagger - Hilt
implementation 'com.google.dagger:hilt-android:2.44.2'
kapt 'com.google.dagger:hilt-android-compiler:2.44.2'
// Room
implementation "androidx.room:room-runtime:2.5.0"
kapt "androidx.room:room-compiler:2.5.0"
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
// Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:2.5.0"
}
project build.gradle
buildscript {
ext {
compose_ui_version = '1.3.3'
}
}
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
id 'com.google.dagger.hilt.android' version '2.44.2' apply false
id "org.jetbrains.kotlin.kapt" version "1.8.0" apply false
}
I updated dependencies highlighted by Android Studio and Compose and was expecting it to work as it was with the new versions. No extra dependencies were added nor was the code modified.
I am making a QR Code Scanner app using Jetpack compose. But when I am trying to use Column, the composable function then the compiler is giving me this error:
Cannot access class 'androidx.compose.ui.Alignment.Horizontal'. Check your module classpath for missing or conflicting dependencies
Here is my app build.gradle module for the app:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.plcoding.qrcodescannercompose"
minSdk 26
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
kotlinCompilerVersion '1.5.21'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation "androidx.compose.ui:ui:$compose_version"
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation("androidx.compose.foundation:foundation:1.0.5")
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
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"
// Activity Compose
implementation "androidx.activity:activity-compose:1.4.0"
// CameraX
implementation "androidx.camera:camera-camera2:1.0.2"
implementation "androidx.camera:camera-lifecycle:1.0.2"
implementation "androidx.camera:camera-view:1.1.0-beta01"
// Zxing
implementation 'com.google.zxing:core:3.3.3'
}
Update: This is the code that is generating the error:
I don't know what this error message is saying and how to resolve this?
Make sure to upgrade your version of Compose to the latest stable version which is 1.1.0-rc03
If your project consists of multiple modules, make sure that all of them are using the same version of Compose.
I am trying to work on an application using Android Studio 4.1 Canary 10 but every time it throws build failed. Following is the error.
Execution failed for task ':app:generateDebugBuildConfig'.
Could not get file details of E:\example\exampleapp\app\build\generated\source\buildConfig\debug: could not file attributes (errno 87)
build.gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.exampleapp"
minSdkVersion 24
targetSdkVersion 29
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'
}
buildFeatures {
compose true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.ui:ui-framework:0.1.0-dev09'
implementation 'androidx.ui:ui-layout:0.1.0-dev09'
implementation 'androidx.ui:ui-material:0.1.0-dev09'
implementation 'androidx.ui:ui-tooling:0.1.0-dev09'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
classpath dependencies :
dependencies {
classpath "com.android.tools.build:gradle:4.1.0-alpha10"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
I did clean and rebuild the project it didn't help. Any help would be great
Thank you
I couldn't to reproduce topic issue. And due to newbie reputation score — comment-section read only for my account now. So I post the answer. Avoid blaming me if it possible, please.
Try to add to application build.gradle file following:
composeOptions {
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
kotlinCompilerExtensionVersion "0.1.0-dev09"
}
just before buildTypes { … } block.
I created a completely fresh jetpack compose project (from the project template) with Android Studio 4.0 Canary 6 and I attempted to add room dependencies.
Here is my app-level build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.composewithroom"
minSdkVersion 29
targetSdkVersion 29
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'
}
buildFeatures {
compose true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.ui:ui-framework:0.1.0-dev03'
implementation 'androidx.ui:ui-layout:0.1.0-dev03'
implementation 'androidx.ui:ui-material:0.1.0-dev03'
implementation 'androidx.ui:ui-tooling:0.1.0-dev03'
implementation "androidx.room:room-runtime:2.2.2"
implementation "androidx.room:room-ktx:2.2.2"
kapt "androidx.room:room-compiler:2.2.2" // e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
I get this error when I try to build it:
e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;
This can be either "fixed" by removing kapt "androidx.room:room-compiler:2.2.2" or disabling compose compose true
Does anyone have any idea how to fix this or is the room database just unusable with Compose at the moment?
Should be fixed in 1.3.61... but Jetpack Compose compiler plugin is not updated.
You can find more information in the following YouTrack issue: IR (Jetpack Compose), KAPT, Room: "AssertionError: IR backend shouldn't call KotlinTypeMapper.mapType: MainActivity". Last comment states that:
The problem here is that JetPack Compose hasn't updated its internal Kotlin compiler to 1.3.61 yet. We'll see what we can do about it.
Also, the following issue in Google Issue Tracker: Annotation processors fail when compose is enabled