Flutter集成Firebase遇build.gradle报错:找不到谷歌服务插件
Flutter集成Firebase时Gradle构建失败问题
报错详情
FAILURE: Build failed with an exception.
- 报错位置:构建文件
C:\Users\82102\Documents\Folder\Coding\Flutter\kyunggi_life\android\app\build.gradle第4行- 问题原因:未找到插件
id: 'com.google.gms.google-services',该插件不在Gradle核心插件中,且插件仓库中未指定版本号官方建议:
- 使用
--stacktrace选项获取堆栈跟踪- 使用
--info或--debug选项获取更多日志- 使用
--scan选项获取完整分析构建1秒后失败,执行Gradle任务
assembleDebug耗时2064ms,最终错误提示:Gradle任务assembleDebug以退出码1失败
已尝试的排查操作
- 耗时约3小时查找解决方案,因理解不足无法应用现有方案
- 推测问题出在
app/build.gradle和android/build.gradle两个配置文件中 - 已执行的修复尝试:
- 在
app/build.gradle中添加ndkVersion "26.1.10909125"、apply plugin: 'com.google.gms.google-services'及任务执行顺序代码 - 检查
android/build.gradle中的buildscript配置,确认已添加google()、mavenCentral()仓库及com.google.gms:google-services:4.3.10的classpath依赖
- 在
相关配置文件代码
app/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 applicationId "com.example.kyunggi_life" 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 }
内容的提问来源于stack exchange,提问作者NOCSML70
相关产品推荐
相关产品推荐

