android Jetpack合成dev06 setContent()无法正常工作?

zfycwa2u  于 2023-03-11  发布在  Android
关注(0)|答案(7)|浏览(152)

在更新到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)
wmvff8tz

wmvff8tz1#

如果您来自dev05、dev04(或更少),则需要进行迁移。
更新:这个逻辑工作到Dev09。测试版目前可用。
我设法让它工作。你需要做以下事情:

*Android Studio 4.1金丝雀2或+
*梯度 Package 器。属性:

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

*版本等级:(项目一级)

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'
}

一旦你完成了所有这些,运行你的代码,你就可以开始了。

beq87vna

beq87vna2#

适用于KotlinDSL

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

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

composeOptions {
    kotlinCompilerExtensionVersion = "1.0.0-beta03"
}
wydwbb8l

wydwbb8l3#

确保在Gradle文件中设置compose true
用于构建版本.gradle.kts

buildFeatures {
        compose = true
 }

适用于传统的build.gradle

buildFeatures {
    compose true
}
eanckbw9

eanckbw94#

在您的应用中构建.gradle应用

buildFeatures {
    compose true
}
composeOptions {
    kotlinCompilerExtensionVersion compose_version
    kotlinCompilerVersion kotlin_compiler_verion
}
uinbv5nw

uinbv5nw5#

我在buildSrc/build.gradle.kts中遇到了相同的错误,即不必要的依赖关系

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

删除后,错误消失。

合成版本1.0.0-beta07

5hcedyr0

5hcedyr06#

我在使用Compose dev07时遇到了同样的错误。我通过在build.gradle(应用程序级别)中提供以下代码修复了该问题:

composeOptions {
        kotlinCompilerExtensionVersion = "0.1.0-dev07" 
}

欲了解更多信息,请点击这里

ut6juiuv

ut6juiuv7#

对于KotlinDSL(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文件-〉
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip

相关问题