I'm trying to build my JetpackCompose project, I'm getting the following error while building the project,

java.lang.IllegalStateException: Function not found androidx.compose.runtime.derived state of

Find below my module-level build.gradle

plugins {
id 'com.android.application'
id 'kotlin-android'
}

android {
compileSdkVersion 30

defaultConfig {
    applicationId "com.example.samplejetpackcompose"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
    compose true
}
composeOptions {
    kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
    kotlinCompilerExtensionVersion "0.1.0-dev13"
}
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.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.ui:ui-tooling:$compose_version"
}

and root level build.gradle is as follows,

buildscript {
ext {
    kotlin_version = "1.4.10"
    compose_version = '1.0.0-alpha03'
}
repositories {
    google()
    jcenter()
}
dependencies {
    classpath "com.android.tools.build:gradle:4.2.0-alpha13"
    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
}
1

There are 1 answers

0
Abhishek Kumar On

I changed composeOption in the module level `app.gradle

composeOptions {
    kotlinCompilerExtensionVersion compose_version
    kotlinCompilerVersion '1.4.10'
}

and in project-level build.gradle

from

compose_version = '1.0.0-alpha03'

to

compose_version = '1.0.0-alpha04'

After changing these things, build happened correctly and my MainActivity.kt adapted the Compose code. But here I started getting another compile-time issue in my MainActivity.kt, where it says

Class 'androidx.compose.runtime.Composition' is compiled by a new Kotlin compiler backend and cannot be loaded by the old compiler

After searching a lot, got this issue fixed by following This Google Compose Link

Simply add the following in your module-level build.gradle

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
    jvmTarget = "1.8"
    freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
}
}