https://kotlinlang.org logo
Title
h

henrikhorbovyi

06/01/2022, 2:36 PM
Hello, everyone 👋 I’m trying to setup compose in an existing project and I’m facing the following error:
NoSuchMethod: No Static method setContent
My dependencies:
dependencies {
    implementation("androidx.core:core-ktx:1.7.0")
    implementation("androidx.compose.ui:ui:1.1.1")
    implementation("androidx.compose.material:material:1.1.1")
    implementation("androidx.compose.ui:ui-tooling-preview:1.1.1")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
    implementation("androidx.activity:activity-compose:1.4.0")

    debugImplementation("androidx.compose.ui:ui-tooling:1.1.1")
    debugImplementation("androidx.compose.ui:ui-test-manifest:1.1.1")
}
kotlinVersion = "1.6.21"
gradlePluginVersion = "7.2.1"
o

Oleksandr Balan

06/01/2022, 2:43 PM
Did you add
buildFeatures
block in your gradle setup? https://developer.android.com/jetpack/compose/interop/adding#config-gradle
☝️ 2
a

Adam Powell

06/01/2022, 2:48 PM
You're not running the compose compiler plugin in the module that includes the call to
setContent
🤔 1
h

henrikhorbovyi

06/01/2022, 2:50 PM
android {
    defaultConfig {
        minSdk = ANDROID_MIN_SDK_VERSION
        compileSdk = ANDROID_COMPILE_SDK_VERSION
        versionCode = System.getenv("VERSION_CODE")?.toIntOrNull() ?: 1
        versionName = PUBLISHING_VERSION
        buildToolsVersion = ANDROID_BUILD_TOOLS_VERSION
    }
    compileOptions {
        sourceCompatibility = VERSION_JAVA
        targetCompatibility = VERSION_JAVA
    }
    sourceSets["main"].java.srcDir("src/main/kotlin")

    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.1.1"
    }
    packagingOptions {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}
a

Adam Powell

06/01/2022, 2:50 PM
If you are loading either the Kotlin or Android Gradle plugins but not both in your
buildSrc
then this can also happen for some non-obvious gradle classpath reasons
🤯 1
h

henrikhorbovyi

06/01/2022, 2:50 PM
That’s my
android
block in build.gradle.kts file
a

Adam Powell

06/01/2022, 2:52 PM
Do you have a
buildSrc
in this project?
h

henrikhorbovyi

06/01/2022, 2:52 PM
Yeah, I have
a

Adam Powell

06/01/2022, 2:53 PM
Does it load the Kotlin gradle plugin or Android gradle plugin?
h

henrikhorbovyi

06/01/2022, 2:53 PM
I created a new module (which is an app) inside a monolithic project
Yeah, it loads
a

Adam Powell

06/01/2022, 2:54 PM
Then have it load both plugins in
buildSrc
h

henrikhorbovyi

06/01/2022, 2:54 PM
That’s my buildSrc/build.gradle.kts
dependencies {
    api("com.android.tools.build:gradle:7.1.2")
    implementation("com.android.tools.build:gradle-api:7.1.2")
    api("com.android.tools.build:bundletool:1.4.0")
    implementation(kotlin("stdlib", "1.6.10"))
    implementation(kotlin("stdlib-jdk8")) // enforcing the same kotlin version to avoiding classpath conflicts
    implementation(kotlin("stdlib-jdk7")) // enforcing the same kotlin version to avoiding classpath conflicts
    implementation(kotlin("reflect"))
    implementation("io.reactivex.rxjava2:rxkotlin:2.4.0")
    implementation("io.reactivex.rxjava2:rxjava:2.2.20")
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:adapter-rxjava2:2.9.0")
    implementation("com.squareup.retrofit2:converter-moshi:2.9.0")
    implementation("com.squareup.moshi:moshi:1.13.0")
    implementation("com.squareup.moshi:moshi-kotlin:1.13.0")
    kapt("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")

    testImplementation("junit:junit:4.13.2")
    testImplementation("io.kotlintest:kotlintest-assertions:3.4.2")
}
a

Adam Powell

06/01/2022, 2:55 PM
They need to be able to see each other from their classloader for agp to configure the compose compiler plugin with the Kotlin gradle plugin
h

henrikhorbovyi

06/01/2022, 3:00 PM
But, Adam… let me see if I got it I load the classpath for
kotlin gradle plugin
and
android gradle plugin
in the build.gradle.kts (from project root) Now I need to load them inside the
buildSrc/build.gradle.kts
, right?
a

Adam Powell

06/01/2022, 3:23 PM
yes. if you load either of these plugins inside your
buildSrc
dependencies {
    implementation("com.android.tools.build:gradle:$androidGradlePluginVersion")
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinGradlePluginVersion")
then you must load both of them together
h

henrikhorbovyi

06/01/2022, 3:25 PM
Ok, I’ll try it Thank you 🙂
@Adam Powell it worked :thank-you: :blob-smile-happy:
👍 1
We are implementing Compose in a project in the company I currently work, I was really excited because it’ll be the first time I’m going to use Compose in a company product. So thank you a lot \o/
🎉 2
a

Adam Powell

06/01/2022, 4:02 PM
happy to help and I'm glad you're excited 😄
:kotlin-intensifies-purple: 1
😄 1
I just filed a bug to the documentation to get this added to the page linked above; hopefully I can stop answering this question soon 😅
👏 2
h

henrikhorbovyi

06/01/2022, 4:24 PM
Cool :cool-doge: Is it open? Can you share it? So I can also document it in the project
a

Adam Powell

06/01/2022, 4:29 PM
hmm, doesn't look like it, I'm afraid. The docs pages have a few extra buttons for filing feedback bugs for us when we look at them and that flow files them under an internal component
👍 1
c

Colton Idle

06/02/2022, 6:21 AM
I think I filed a bug for this wayyyyy back. https://issuetracker.google.com/issues/176079157
I will chat with the Documentation folks so we make it clearer in our Compose documentation.
😭
I definitely opened another bug for this to be documented after it happened to me again, but I remember someone closing it basically saying that its not composes responsibility to let people know about this.
🤔 1
Ill look for it tomorrow. must. sleep.
Oh yeah. Last year. Jim seemed to disuade against it... plus he tagged adam. 😂 Its come full circle. I tried to be a good compose citizen. /shruggie https://kotlinlang.slack.com/archives/CJLTWPH7S/p1623347985410800?thread_ts=1623270940.306300&cid=CJLTWPH7S
😄 1
h

henrikhorbovyi

06/02/2022, 6:04 PM
Thanks for sharing it, @Colton Idle Hope that will be documented or at least giving us a proper error message soon 🙂