【问题标题】:Jetpack Compose setup issue: Unable to load class 'org.jetbrains.kotlin.gradle.tasks.KotlinCompile'Jetpack Compose 设置问题:无法加载类 'org.jetbrains.kotlin.gradle.tasks.KotlinCompile'
【发布时间】:2020-12-24 21:15:55
【问题描述】:

我有一个新的 Android 项目,我想使用 Jetpack Compose,但是按照outlined here 的步骤操作会出现以下构建错误:

Unable to load class 'org.jetbrains.kotlin.gradle.tasks.KotlinCompile'.

This is an unexpected error. Please file a bug containing the idea.log file.

也许我使用 Kotlin DSL build.gradle.kts 使问题更加复杂,但这是我的 gradle 设置:

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("kotlin-kapt")
    id("dagger.hilt.android.plugin")
}

android {
    compileSdkVersion(30)

    defaultConfig {
        applicationId = "..."
        minSdkVersion(24)
        targetSdkVersion(30)
        versionCode = 1
        versionName = "1.0"
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
        }
    }

    compileOptions {
        sourceCompatibility(JavaVersion.VERSION_1_8)
        targetCompatibility(JavaVersion.VERSION_1_8)
    }

    buildFeatures {
        dataBinding = true
        compose = true
    }

    kotlinOptions {
        jvmTarget = "1.8"
        useIR = true
    }

    composeOptions {
        kotlinCompilerVersion = "1.4.20"
        kotlinCompilerExtensionVersion = "1.0.0-alpha08"
    }
}

dependencies {
    implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
    //...

}

【问题讨论】:

  • 你解决了吗?

标签: android kotlin android-jetpack-compose


【解决方案1】:

试试 '1.0.0-alpha09' 和 Kotlin 版本“1.4.21”,你应该很高兴。

你的构建脚本中有这个吗?

buildscript {
    ext {
        compose_version = '1.0.0-alpha09'
    }
    ext.kotlin_version = "1.4.21"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    • 2022-11-07
    • 2023-02-03
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    相关资源
    最近更新 更多