我是 flutter 新手,我正在尝试运行我的应用程序,并且我得到这个“kotlin-android”插件需要 Android Gradle 插件之一。
这是我尝试运行该应用程序时显示的错误。
失败:构建失败并出现异常。
'kotlin-android' 插件需要 Android Gradle 插件之一。 请将以下插件之一应用到“:”项目:
尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。使用 --scan 运行以获得完整的见解。
11秒后构建失败 异常:Gradle 任务 assembleDebug 失败,退出代码为 1
这是我的 android/app/build gradle 文件
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the
local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion flutter.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID
(https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.woerrortisunmi"
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
//classpath "com.android.tools.build:gradle-settings:7.4.2."
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:30.0.2')
implementation 'com.google.firebase:firebase-auth'
implementation 'androidx.browser:browser:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
这是我的 Android/BUILD-GRADLE 文件
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
// gradlePluginPortal()
google()
//mavenCentral()
maven {
url 'https://dl.google.com/dl/android/maven2'
}
jcenter()
//url "https://plugins.gradle.org/m2/"
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
//classpath 'com.android.tools.build:gradle-settings:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google()
//mavenCentral()
maven {
url 'https://dl.google.com/dl/android/maven2'
}
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: "org.jetbrains.kotlin.android"
提前致谢
你的build.gradle应该是这样的
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
maven {
url 'http://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:1.5.25'
classpath 'com.google.gms:google-services:4.3.2'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
如果上述解决方案失败,您可以尝试在settings.gradle中查找kotlin版本