Flutter打包APK报错:Could not get unknown property 'android' for :firebase_core
Flutter构建APK失败:Could not get unknown property 'android' for project ':firebase_core'
尝试执行flutter build apk构建Android应用时失败,报错信息如下:
FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring project ':firebase_core'. > Failed to notify project evaluation listener. > Could not get unknown property 'android' for project ':firebase_core' of type org.gradle.api.Project. > Could not get unknown property 'android' for project ':firebase_core' of type org.gradle.api.Project. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. BUILD FAILED in 953ms Running Gradle task 'assembleRelease'... 1.604ms Gradle task assembleRelease failed with exit code 1
当前配置文件
settings.gradle
include ':app' include ':firebase_core' project(':firebase_core').projectDir = new File(rootProject.projectDir, '../../AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core-3.9.0/android')
项目级build.gradle
buildscript { ext { compileSdkVersion = 33 minSdkVersion = 21 targetSdkVersion = 33 } repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:8.0.2' classpath 'com.google.gms:google-services:4.3.15' } } allprojects { repositories { google() mavenCentral() } }
应用级build.gradle
android { compileSdkVersion 33 defaultConfig { applicationId "com.gustaga.app" minSdkVersion 21 targetSdkVersion 33 versionCode 1 versionName "1.0" } buildTypes { release { signingConfig signingConfigs.debug minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } flutter { source = "../.." } dependencies { implementation project(':firebase_core') implementation 'com.google.firebase:firebase-core:21.1.1' implementation 'com.google.firebase:firebase-database:20.0.5' implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' }
firebase_core的build.gradle
buildscript { repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:8.0.2' } } apply plugin: 'com.android.library' android { compileSdkVersion 33 defaultConfig { minSdkVersion 21 targetSdkVersion 33 } lintOptions { disable 'InvalidPackage' } } dependencies { implementation 'com.google.firebase:firebase-core:21.1.1' }
解决步骤
修正settings.gradle:移除手动添加的
:firebase_core相关行,恢复为Flutter默认配置,示例如下:include ':app' apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"(注:若使用Flutter新版本,settings.gradle可能采用
plugins块结构,保持默认即可)通过pub管理依赖:确保
pubspec.yaml中正确声明firebase_core依赖:dependencies: flutter: sdk: flutter firebase_core: ^3.9.0执行
flutter pub get拉取依赖。清理应用级build.gradle:移除
dependencies中的implementation project(':firebase_core'),Flutter插件会自动处理依赖关联。移除自定义firebase_core构建配置:删除手动修改的firebase_core本地build.gradle,使用pub下载的插件自带配置即可。
重新构建:执行
flutter clean后,再运行flutter build apk。
内容的提问来源于stack exchange,提问作者Cristian Osorio
相关产品推荐
相关产品推荐

