android - Jetpack Compose 无法编译应用程序,找不到 kotlin-compiler

标签 android kotlin android-jetpack android-jetpack-compose

最近我一直在努力让 jetpack compose 运行......我已经按照所有示例代码,下载了 canary 和所有,但是 1.4.0 插件对我不起作用,我遇到了编译问题
这些是我的 gradle 文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.4.0"
    ext.compose_version = '1.0.0-alpha01'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.0-alpha08"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.jetexample"
        minSdkVersion 21
        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'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion kotlin_version
        kotlinCompilerVersion compose_version
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'

    //Fundamental building blocks of Compose's programming model and state management, and core runtime for the Compose Compiler Plugin to target.
    implementation "androidx.compose.runtime:runtime:$compose_version"

    //Fundamental components of compose UI needed to interact with the device, including layout, drawing, and input.
    implementation "androidx.compose.ui:ui:$compose_version"

    //Build Jetpack Compose UIs with ready to use Material Design Components. This is the higher level entry point of Compose, designed to provide components that match those described at www.material.io.
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.material:material-icons-extended:$compose_version"

    //Write Jetpack Compose applications with ready to use building blocks and extend foundation to build your own design system pieces.
    implementation "androidx.compose.foundation:foundation:$compose_version"
    implementation "androidx.compose.foundation:foundation-layout:$compose_version"

    //Build animations in their Jetpack Compose applications to enrich the user experience.
    implementation "androidx.compose.animation:animation:$compose_version"

    //In charge of annotators like @Preview and tooling for render views
    implementation "androidx.ui:ui-tooling:$compose_version"

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
我得到的错误是这个
Could not resolve compiler classpath. Check if Kotlin Gradle plugin repository is configured in project ':app'.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugAndroidTestKotlin'.
> Could not resolve all files for configuration ':app:kotlinCompilerClasspath'.
   > Could not find org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.0-alpha01.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.0.0-alpha01/kotlin-compiler-embeddable-1.0.0-alpha01.pom
       - https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.0.0-alpha01/kotlin-compiler-embeddable-1.0.0-alpha01.pom
     Required by:
         project :app
   > Could not find org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.0-alpha01.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.0.0-alpha01/kotlin-compiler-embeddable-1.0.0-alpha01.pom
       - https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.0.0-alpha01/kotlin-compiler-embeddable-1.0.0-alpha01.pom
     Required by:
         project :app
我已经尝试过这个版本,我遵循了文档、jet news 示例和所有内容,但我无法编译项目,我做错了什么?

最佳答案

我与 compileOptions 不匹配

 composeOptions {
        kotlinCompilerExtensionVersion kotlin_version
        kotlinCompilerVersion compose_version
    }
应该
composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion kotlin_version
    }

关于android - Jetpack Compose 无法编译应用程序,找不到 kotlin-compiler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63709220/

相关文章:

Android回调和监听器的区别

android - 如何将我的自定义 ImageView 与 DataBinding 一起使用?

android - VLC 实时 http 流式传输到 Android

Android 应用程序被 SyncAdapter 杀死

android - 我可以使用 Google 云端硬盘代替服务器吗

android - 如何修复 DefaultKotlinSourceSetKt 的初始化错误?

android - 在主/从流程中切换 fragment

android - 在 onBindViewHolder 之外使用 ViewHolder 元素?

android - Google 为新的 Android 应用架构推荐的文件结构

android - 如何在 JetPack Navigation 组件中托管 fragment 的 Activity 中调用导航 fragment 函数?