gpt4 book ai didi

android - 尝试设置 Jetpack Compose 时遇到问题 找到接口(interface) rPluginContext

转载 作者:行者123 更新时间:2023-12-05 00:19:15 24 4
gpt4 key购买 nike

所以,我试图让 jetpack compose 运行一个简单的例子,我已经将我的 kotlin 插件更新到 1.4.0 并且还使用 jetpack compose 文档更新了我的所有构建 gradle,但是在编译时出现了这个错误

java.lang.IncompatibleClassChangeError: Found interfaceorg.jetbrains.kotlin.backend.common.extensions.IrPluginContext, butclass was expected atandroidx.compose.plugins.kotlin.ComposeIrGenerationExtension.generate(ComposeIrGenerationExtension.kt:41)


我也下载了安卓工作室的金丝雀版
build.gradle 项目
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.0-rc"
repositories {
google()
jcenter()
maven{
url "https://dl.bintray.com/kotlin/kotlin-eap/"
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
maven{
url "https://dl.bintray.com/kotlin/kotlin-eap/"
}
}
}

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 30
buildToolsVersion "30.0.1"

defaultConfig {
applicationId "com.jetpackcompose"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

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

// Set both the Java and Kotlin compilers to target Java 8.

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

composeOptions {
kotlinCompilerVersion kotlin_version
kotlinCompilerExtensionVersion "0.1.0-dev13"
}
}

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


implementation 'androidx.ui:ui-core:0.1.0-dev13'
implementation 'androidx.ui:ui-tooling:0.1.0-dev13'
implementation 'androidx.ui:ui-layout:0.1.0-dev13'
implementation 'androidx.ui:ui-material:0.1.0-dev13'


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


tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
}
}
但我无法编译应用程序,我正在尝试运行基本示例
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent{
sayHello()
}
}

@Preview
@Composable
fun sayHello(){
Text("Hello World")
}
}
有谁知道为什么会抛出这个错误?

最佳答案

使用 Kotlin 版本 1.4.10 而不是 1.4.20 解决了我的问题。

关于android - 尝试设置 Jetpack Compose 时遇到问题 找到接口(interface) rPluginContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63457702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com