android-gradle-plugin - build.gradle 文件无法编译
问题描述
运行项目时出现此错误:
无法编译构建文件'H:\StartActivity\build.gradle'
。
启动失败:构建文件 'H:\StartActivity\build.gradle': 28: 在 plugins {} 块之前只允许 buildscript {} 和其他插件 {} 脚本块,不允许其他语句
// 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{...}
// 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
}
}
....
推荐阅读
- java - 在 apache camel 中将 json 转换为其他格式
- python - 检测股票市场数据中的牛旗模式
- java - 简单猜猜android studio上的数字游戏应用。在我的物理设备中运行 apk 时,它会立即强制关闭
- machine-learning - 特征选择——降噪
- oracle - 使用 OLEDB Provider 与 Oracle 数据库的 UDL 连接
- sql - 如何使“插入”在每次插入表时返回一个值?
- reactjs - 如何设置appium max sanpshot depth
- javascript - 如何使用文件路径使用 reactjs 或 javascript 读取 excel 文件中的数据
- ios - Xamarin IOS 发布失败 CFRULRequestSetHTTPCookiesStorageAcceptPolicy
- typescript - 未找到模块 - 打字稿 cli