android - Unresolved reference : android build failed with kotlin dsl (reproducible in an empty project)

标签 android android-studio kotlin gradle-kotlin-dsl

我的build.gradle.kts(:app):

plugins {


    id("com.android.application")
    kotlin("plugin.serialization") version "1.4.21-release-Studio4.2-1"
    kotlin("android")
    kotlin("android.extensions")
    kotlin("kapt")
}

android {
    compileSdkVersion (30)
    buildToolsVersion ("30.0.2")
    defaultConfig {
        applicationId ="learnprogramming.academy.relaf"
        minSdkVersion(24)
        targetSdkVersion(30)
        versionCode =1
        versionName ="1.0"
        testInstrumentationRunner ="androidx.test.runner.AndroidJUnitRunner"
        javaCompileOptions {
            annotationProcessorOptions {
                arguments["room.incremental"] = "true"
            }
        }
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = true
            proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
        }
    }
    buildFeatures {
        // Enables Jetpack Compose for this module
        compose = true
    }
    compileOptions {
        sourceCompatibility= JavaVersion.VERSION_1_8
        targetCompatibility= JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
        useIR = true
    }
    composeOptions {
        kotlinCompilerVersion= "1.4.21-release-Studio4.2-1"
        kotlinCompilerExtensionVersion= "1.0.0-alpha08"
    }
}
dependencies {

    val composeVersion = "1.0.0-alpha08"
//    implementation ("androidx.compose.runtime:runtime:$composeVersion")
//    implementation ("androidx.compose.compiler:compiler:$composeVersion")
//    implementation ("androidx.compose.ui:ui:$composeVersion")
    // Tooling support (Previews, etc.)
    implementation ("androidx.compose.ui:ui-tooling:$composeVersion")
    // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
    implementation ("androidx.compose.foundation:foundation:$composeVersion")
    // Material Design
    implementation ("androidx.compose.material:material:$composeVersion")
    // Material design icons
    implementation ("androidx.compose.material:material-icons-core:$composeVersion")
    implementation ("androidx.compose.material:material-icons-extended:$composeVersion")
    // Integration with observables
    implementation ("androidx.compose.runtime:runtime-livedata:$composeVersion")

    val roomVersion = "2.3.0-alpha04"

    implementation( "androidx.room:room-runtime:$roomVersion")
    kapt ("androidx.room:room-compiler:$roomVersion")
    val kotlin_version = "1.4.21"
    implementation ("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version")
    implementation( "androidx.appcompat:appcompat:1.3.0-alpha02")
    testImplementation ("junit:junit:4.12")
    implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
    // optional - Kotlin Extensions and Coroutines support for Room
    implementation ("androidx.room:room-ktx:$roomVersion")
    // ViewModel and LiveData
    val lifecycle_version = "2.2.0"
    implementation ("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
    implementation ("androidx.lifecycle:lifecycle-extensions:$lifecycle_version")
    implementation ("androidx.fragment:fragment-ktx:1.2.2")
    // RecyclerView
    implementation ("androidx.recyclerview:recyclerview:1.0.0")
    implementation ("com.google.android.material:material:1.3.0-alpha03")
    implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
    implementation ("com.android.volley:volley:1.1.1")
    implementation("org.jsoup:jsoup:1.13.1")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
    implementation ("androidx.core:core-ktx:1.0.2")
    implementation ("androidx.constraintlayout:constraintlayout:1.1.3")
    androidTestImplementation ("androidx.test.ext:junit:1.1.0")
    androidTestImplementation( "androidx.test.espresso:espresso-core:3.1.1")
}

我的另一个 build.gradle.kts(前 10 个下载器):

buildscript {
    val kotlin_version = "1.4.21"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath ("com.android.tools.build:gradle:7.0.0-alpha03")
        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()
    }
}

tasks.register("clean",Delete::class){
    delete(rootProject.buildDir)
}

我的settings.gradle.kts:

include (":app")
rootProject.name="Top 10 Downloader"

它可以在一个空项目中重现。我正在使用最新的 canary android studio arctic fox。我做错了什么?

最佳答案

确定发现错误。最新的 canary android studio 更新了我的 gradle 版本,并且由于 gradle 更新,build.gradle 中的 buildFeatures { compose = true } 导致 gradle 永远运行,因为我使用的是现在已弃用的 kotlin 合成。所以在最新的 gradle (7) 中,使用合成(不仅仅是添加)和 IMPORTINGbuildFeatures { compose = true } 导致 gradle 无限循环。

关于android - Unresolved reference : android build failed with kotlin dsl (reproducible in an empty project),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65519299/

相关文章:

java - 如何在 GridView 中交换图像 (Android)

Android Studio 导出库\SDK 不暴露代码

functional-programming - 使用arrow-kt的列表理解时的ClassCastException

android - 作业失败,出现异常 : System. Reflection.TargetInitationException Unity 错误

android - TextView 滚动问题

java - Android 基础数学不及格

android - 如何将库项目添加到 Android Studio?

android - 应用程序图标仅在模拟器上显示

kotlin - 不能使用提供的参数调用以下函数

android - 太多的 XML 数据绑定(bind)