尝试设置Jetpack Compose Found接口rPluginContext时出现问题

问题描述

因此,我试图通过一个简单的示例运行jetpack compose,我已经将我的kotlin插件更新为1.4.0,并且还使用jetpack compose文档更新了我的所有构建版本,但是在编译时出现了此错误

java.lang.IncompatibleClassChangeError:找到接口 org.jetbrains.kotlin.backend.common.extensions.IrPluginContext,但是 预计在 androidx.compose.plugins.kotlin.ComposeIrGenerationExtension.generate(ComposeIrGenerationExtension.kt:41)

我还下载了Android Studio的金丝雀版本

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解决了我的问题。

,

尝试将Compose版本更新为0.1.0-dev16。看来0.1.0-dev13与Kotlin 1.4-rc

不兼容

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...