One Off the Slack: Where Did My setContent() Go?

Henrique Horbovyi asked:

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")
}

Google’s Adam Powell offered:

You’re not running the compose compiler plugin in the module that includes the call to setContent

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

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


Read the original thread in the kotlinlang Slack workspace. Not a member? Join that Slack workspace here!