Jetpack Compose dev06 setContent()无法正常工作吗? [英] Jetpack Compose dev06 setContent() doesn't work?

查看:97
本文介绍了Jetpack Compose dev06 setContent()无法正常工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在更新至dev06并运行应用程序时,出现以下错误:

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)

推荐答案

如果您来自dev05,dev04(或以下),则需要进行迁移.

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

更新:此逻辑适用于Dev09.BETA版本目前可用.

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或+
  • 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'
    }
    

    完成所有操作后,运行代码,您就可以开始工作了.

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

    这篇关于Jetpack Compose dev06 setContent()无法正常工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆