Jetpack Compose dev06 setContent () не работает? - PullRequest
4 голосов
/ 10 марта 2020

При обновлении до dev06 и запуске приложения я получил следующую ошибку:

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)

Ответы [ 2 ]

19 голосов
/ 11 марта 2020

Если вы работаете с dev05, dev04 (или меньше), необходимо выполнить миграцию.

Мне удается заставить его работать. Вам необходимо сделать следующее:

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

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

  • build.gradle: (уровень проекта)
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 (уровень приложения):
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'
}

Как только вы все это сделаете, запустите свой код, и вам будет хорошо go.

0 голосов
/ 27 апреля 2020

Я получил ту же ошибку при использовании Compose dev07. Я исправил проблему, указав следующий код в build.gradle (уровень приложения):

composeOptions {
        kotlinCompilerExtensionVersion = "0.1.0-dev07" 
}

Для получения дополнительной информации, пожалуйста, проверьте здесь

...