我将一起使用 flutter 和 firebase。我将完成 Firebase 设置并尝试再次运行该应用程序,但出现以下错误。
失败:构建失败并出现异常。
地点: 构建文件'C:\Users\82102\Documents\Folder\Coding\Flutter\kyunggi_life ndroid pp uild.gradle'行:4
出了什么问题: 在以下任何来源中均未找到插件 [id: 'com.google.gms.google-services']:
使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获得更多日志输出。 使用 --scan 运行以获得完整的见解。 在 https://help.gradle.org 获取更多帮助。
1秒内构建失败 运行 Gradle 任务“assembleDebug”... 2,064ms 错误:Gradle 任务 assembleDebug 失败,退出代码为 1
我已经尝试解决这个问题大约三个小时了。我见过类似问题的解决方案,但我无法应用它们,因为我不太理解它们。
从某种程度上看来,以下2段代码肯定有问题。
应用程序/build.gradle
plugins {
id "com.android.application"
// START: FlutterFire Configuration
id 'com.google.gms.google-services'
// END: FlutterFire Configuration
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace "com.example.kyunggi_life"
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
ndkVersion "26.1.10909125"
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.kyunggi_life"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
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
}
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'processDebugGoogleServices') {
task.mustRunAfter 'mapDebugSourceSetPaths'
}
}
flutter {
source '../..'
}
dependencies {}
apply plugin: 'com.google.gms.google-services'
android/build.gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
我通过互联网搜索尝试了以下方法。
添加
ndkVersion "26.1.10909125"
,
apply plugin: 'com.google.gms.google-services'
,
tasks.whenTaskAdded { task ->
if (task.name == 'processDebugGoogleServices') {
task.mustRunAfter 'mapDebugSourceSetPaths'
}
}
在应用程序/build.gradle
检查
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.google.gms:google-services:4.3.10'
}
}
```,
in android/build.gradle
要解决 Flutter 项目中 com.google.gms.google-services 插件的问题,
请按照以下步骤操作:
确保包含 Google 服务依赖项:确保在 android/build.gradle 文件的 buildscript 部分中正确指定类路径“com.google.gms:google-services:4.3.10”。
将插件添加到应用程序级构建文件:验证 apply plugin: 'com.google.gms.google-services' 行是否存在于 android/app/build.gradle 文件的底部。
存储库配置:确保 google() 和 mavenCentral() 存储库都包含在您的 android/build.gradle 文件中。
以下是确保您的配置正确的清单和步骤:
android/build.gradle 文件: 确保你的 android/build.gradle 看起来像这样:
摇篮 复制代码
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
android/app/build.gradle 文件: 确保您的 android/app/build.gradle 包含以下配置:
摇篮
复制代码
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id 'com.google.gms.google-services' // <-- Ensure this line is here
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace "com.example.kyunggi_life"
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "com.example.kyunggi_life"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'processDebugGoogleServices') {
task.mustRunAfter 'mapDebugSourceSetPaths'
}
}
flutter {
source '../..'
}
dependencies {
// Add any additional dependencies here
}
apply plugin: 'com.google.gms.google-services' // <-- Ensure this line is here
常见问题:
插件放置不正确:确保 apply plugin: 'com.google.gms.google-services' 位于 app/build.gradle 文件底部,依赖项部分之后。
版本冲突:确保所有版本兼容。例如,您的 com.android.tools.build:gradle 版本应与您的 Android Studio 版本和 google-services 插件兼容。
进行这些更改后,清理并重建您的项目:
复制代码
flutter clean
flutter pub get
flutter build apk
谢谢你。