我试图将Firebase添加到我的flutter项目中,但是当我在调试模式下运行它时,我得到了一个错误。
如何将Firebase SDK添加到我的项目中的说明显示,我的build.gradle
文件与Google所说的应该是不同的。我已经查找了一些东西,我认为我已经向文件中添加了正确的行。
以下是将Firebase SDK添加到我的flutter项目的说明:
这是我的项目>android>app>build.gradle文件:
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id "com.google.gms.google-servides"
}
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.myapp"
compileSdkVersion 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 {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.deal_diligence"
// 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
}
}
}
flutter {
source '../..'
}
dependencies {
implementation(platform("com.google.firebase:firebase-bom:32.3.1"))
}
下面是project>android>build.gradle中的build.gradle
文件:
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.4.0'
}
plugins {
id("com.google.gms.google-services") version "4.4.0" apply false <<< ERROR HERE
}
}
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
}
这是我得到的错误:FAILURE: Build failed with an exception.
- 其中:构建文件“C:\deal_diligence\deal_diligence\android\build.gradle”行:14
- 哪里出错了:评估根项目“android”时出现问题。
在类型为org.gradle.api.internal.initialization.DefaultScriptHandler的对象上找不到参数[build_c3pybmo0bbk86suaedh5ircie$_run_closure1$_closure4@7f9d876a]的方法插件()。
我应该有所有的最新和最伟大的,因为我昨天创建了这个项目。如何修复此错误?谢谢
1条答案
按热度按时间1szpjjfi1#
既然你说你说这是一个Flutter应用程序,我建议按照文档中的步骤来setting up Firebase in a Flutter app。无需为此修改任何Gradle文件。