9
votes

While updating to dev06 and ran the app I got the following error:

java.lang.NoSuchMethodError: No static method setContent(Landroid/app/Activity;Lkotlin/jvm/functions/Function0;)Landroidx/compose/Composition; in class Landroidx/ui/core/WrapperKt; or its super classes (declaration of 'androidx.ui.core.WrapperKt' appears in /data/app/tt.reducto.composesample-BYNjMDWbVhiprnPCNJw0LA==/base.apk)
6
I'm also hitting this after upgrading from dev4 to dev6, so it's not just you.user1713450
Starting in alpha12 you'll need to add a dependency on androidx.activity:activity-compose as shown in this answerRosário Pereira Fernandes

6 Answers

23
votes

If you're coming from dev05, dev04 (or less), there's a migration needed.

UPDATE: This logic works up to Dev09. BETA Release is currently available.

I manage to make it work. You need to do the following:

  • Android Studio 4.1 Canary 2 or +
  • gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip

  • build.gradle: (project level)
buildscript {
    ext.kotlin_version = "1.3.70"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.0-alpha02"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  • build.gradle (app level):
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "com.package.name"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    composeOptions {
        kotlinCompilerExtensionVersion = "0.1.0-dev06" // THIS ONE is important
    }

    buildFeatures {
        compose 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'
    }
}

dependencies {

    def compose_version = "0.1.0-dev06"

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation "androidx.ui:ui-foundation:$compose_version"
    implementation "androidx.ui:ui-framework:$compose_version"
    implementation "androidx.ui:ui-tooling:$compose_version"

    implementation "androidx.ui:ui-layout:$compose_version"
    implementation "androidx.ui:ui-material:$compose_version"

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Once you get all that done, run your code and you'd be good to go.

2
votes

I got the same error while used Compose dev07. I fixed the issue by giving the below code in build.gradle (app level):

composeOptions {
        kotlinCompilerExtensionVersion = "0.1.0-dev07" 
}

For more info please check here

2
votes

I had the same error with unnecessary dependency in buildSrc/build.gradle.kts

dependencies {
    implementation("com.android.tools.build:gradle:7.0.0-beta02")
}

After removing this the error is gone.

compose version 1.0.0-beta07

2
votes

For Kotlin DSL

kotlinOptions {
    jvmTarget = V.JVM.Kotlin.target
    useIR = true
}

buildFeatures {
//    Enables Jetpack Compose for this module
    compose = true
}

composeOptions {
    kotlinCompilerExtensionVersion = "1.0.0-beta03"
}
1
votes

In you apps build.gradle app

 buildFeatures {
    compose true
}
composeOptions {
    kotlinCompilerExtensionVersion compose_version
    kotlinCompilerVersion kotlin_compiler_verion
}
0
votes

For Kotlin DSL(build.gradle.kts):

android {
    buildFeatures {
        compose = true
        composeOptions.kotlinCompilerExtensionVersion = Depends.Versions.composeVersion //"1.0.0-alpha08"
        composeOptions.kotlinCompilerVersion = Depends.Versions.kotlinVersion //"1.4.20"
    }

gradle-wrapper.properties file ->
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip