android - Jetpack Compose dev06 setContent() 不起作用?
问题描述
更新到 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)
解决方案
如果您来自 dev05、dev04(或更少),则需要迁移。
更新:此逻辑适用于 Dev09。BETA 版本目前可用。
我设法使它工作。您需要执行以下操作:
- 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'
}
一旦你完成了所有这些,运行你的代码,你就可以开始了。
推荐阅读
- c - 如何在 c 中添加子集中的项目并将它们存储在某个数组或某个数据类型中,以便我可以访问每个总和以进行进一步比较?
- android - React native 无法启动模拟器
- javascript - 函数可能写错了,不切换图像
- php - 请求非根位置时的 NGINX 404
- active-directory - 从 Windows SID 中提取 RID
- scikit-learn - XGBoost:在默认指标上提前停止,而不是自定义评估函数
- r - R如何从中断的倒置钟形曲线中采样
- php - 在 wordpress 中,我可以在我的主题中使用 PHP 添加一个新类别吗
- python - 我需要不在 Python 列表中的 for 循环中的数字总和
- shell - 如何从数组运行 bash 命令?