本文介绍了build.gradle 文件无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行项目时出现此错误:
This error appears when I run my project:
无法编译构建文件 'H:\StartActivity\build.gradle'
.
启动失败:build file 'H:\StartActivity\build.gradle': 28: 只允许 buildscript {} 和其他插件 {} 脚本块在 plugins {} 块之前,不允许其他语句
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.0-release-764"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
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()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.5.0-release-764'
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
推荐答案
你应该在 allprojects{...} 之前移动 plugins{...}
You should move plugins{...} before allprojects{...}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.0-release-764"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
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
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.5.0-release-764'
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
....
这篇关于build.gradle 文件无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!