gpt4 book ai didi

android - build.gradle 文件中的 compileKotlin block 抛出错误 "Could not find method compileKotlin() for arguments [...]"

转载 作者:IT老高 更新时间:2023-10-28 13:26:58 28 4
gpt4 key购买 nike

我正在尝试将 Kotlin 配置为在我的 Android 项目中使用 Java 1.8。我尝试在 build.gradle 文件的底部添加 compileKotlin block ,但如果这样做会出现错误。

发生的错误如下:

Error:(38, 0) Could not find method compileKotlin() for arguments [build_dvcqiof5pov8xt8flfud06cm3$_run_closure4@66047120] on project ':core' of type org.gradle.api.Project.

没有这个 block ,项目运行良好。我错过了什么?这是完整的 build.gradle 文件,它是非常基本的东西:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'


android {
compileSdkVersion 25
buildToolsVersion '25.0.2'


defaultConfig {
minSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName '1.0.0'

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

}

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

dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.google.android.support:wearable:2.0.2'
}

repositories {
mavenCentral()
}

compileKotlin {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

kotlinOptions {
jvmTarget = '1.8'
apiVersion = '1.1'
languageVersion = '1.1'
}
}

最佳答案

您收到的错误意味着项目中没有 compileKotlin 任务,这是 Android 项目所期望的。

Android 项目中的 Kotlin 编译任务名称包含 build variant名称(这些由构建类型、产品风格和其他设置组合而成,类似于 debugreleaseUnitTest - 任务是 compileDebugKotlincompileReleaseUnitTestKotlin)。没有compileKotlin任务,一般是为普通Java+Kotlin项目中的main源码集创建的。

很可能,您想在项目中配置所有 Kotlin 编译任务,为此,您可以按如下方式应用该 block :

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

kotlinOptions {
jvmTarget = '1.8'
apiVersion = '1.1'
languageVersion = '1.1'
}
}

关于android - build.gradle 文件中的 compileKotlin block 抛出错误 "Could not find method compileKotlin() for arguments [...]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44141076/

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