Hi. I have some problem with Jetpack Compose in a ...
# android
p
Hi. I have some problem with Jetpack Compose in a Kotlin MPP project. Here is my gradle file for android application:
Copy code
plugins {
    kotlin("multiplatform")
    id("com.android.application")
}

group = "me.user"
version = "1.0-SNAPSHOT"

kotlin {
    android()
    sourceSets {
        val androidMain by getting {
            dependencies {
                val compose_version = "1.2.0-beta02"
                implementation(project(":shared"))
                implementation("androidx.core:core-ktx:1.7.0")
                implementation("androidx.compose.ui:ui:$compose_version")
                implementation("androidx.compose.runtime:runtime:$compose_version")
                implementation("androidx.compose.ui:ui-tooling:$compose_version")
                implementation("androidx.compose.foundation:foundation:$compose_version")
                implementation("androidx.compose.ui:ui-tooling-preview:$compose_version")
                implementation("androidx.compose.material:material:$compose_version")
                implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
                implementation("androidx.activity:activity-compose:1.4.0")
                implementation("com.google.android.material:material:1.5.0")
                implementation("androidx.appcompat:appcompat:1.4.1")
                implementation("androidx.constraintlayout:constraintlayout:2.1.3")
            }
        }
    }
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

android {
    compileSdkVersion(32)
    defaultConfig {
        applicationId = "me.user.androidApp"
        minSdkVersion(24)
        targetSdkVersion(32)
        versionCode = 1
        versionName = "1.0"
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.2.0-beta02"
    }
}
But the problem is that application fails to build with
Copy code
Caused by: java.lang.IllegalStateException: couldn't find inline method Landroidx/compose/runtime/ComposablesKt;.remember(Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
	at org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.getMethodNode(SourceCompilerForInline.kt:118)
	at org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.loadCompiledInlineFunction(SourceCompilerForInline.kt:96)
	at org.jetbrains.kotlin.backend.jvm.codegen.IrSourceCompilerForInline.compileInlineFunction(IrSourceCompilerForInline.kt:90)
	at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:47)
	... 67 more
Kotlin is 1.6.21 AGP version 7.2.1 I have
Copy code
buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.2.0-beta02"
    }
In my
shared
module as well (edited)
e
you need to enable the compose compiler plugin in your application build as well
I'm not sure if the android plugin works with mpp though
have you tried making it a plain android application module (no mpp)?
p
Yes, everything works in android without MPP. It turns out to be a known issue. https://youtrack.jetbrains.com/issue/KT-38694 Here is a workaround to make compose work with mpp https://github.com/avdim/compose_mpp_workaround
235 Views