如何修复Flutter项目中的“FirebaseCoreHostApi.optionsFromResource”错误?

t5zmwmid  于 2023-10-22  发布在  Flutter
关注(0)|答案(1)|浏览(125)

主省道:

import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}

class MyApp extends StatefulWidget {
@override
\_MyAppState createState() =\> \_MyAppState();

我的依赖:相关性:地理定位器:^9.0.2Flutter:sdk:flutter intl:任何firebase_core:任何firebase_auth:cloud_firestore:任何firebase_analytics:任何firebase_core_platform_interface:任何flutter_local_notifications:任何shared_preferences:任何设备信息:任何table_calendar:任何flutter_datetime_picker:任何地理编码:任何库比蒂诺_图标:任何地点:任何permission_handler:任何google_maps_flutter:任何firebase_database:任何excel:任何path_provider:任何
我的应用\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 33
buildToolsVersion "33.0.0"
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 {
        minSdkVersion 20
        multiDexEnabled true
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.picar_dlava"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        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 'androidx.multidex:multidex:2.0.1'
implementation platform('com.google.firebase:firebase-bom:32.0.0')
implementation 'com.google.firebase:firebase-analytics:17.5.0'
}

我的andoird\build.gradle:

buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
    }

}

allprojects {
repositories {
google()
mavenCentral()
}
}

rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
delete rootProject.buildDir
}

我一直得到这个错误:

n value., null, null)
E/flutter (12308): #0      FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
E/flutter (12308): \<asynchronous suspension\>
E/flutter (12308): #1      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter (12308): \<asynchronous suspension\>
E/flutter (12308): #2      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter (12308): \<asynchronous suspension\>
E/flutter (12308): #3      main (package:picagem_dalva/main.dart:14:3)
E/flutter (12308): \<asynchronous suspension\>
E/flutter (12308):

我已经搬迁了我的谷歌服务,没有工作

rhfm7lfc

rhfm7lfc1#

在我的情况下,我解决下面的解决方案。
我的应用\build.gradle:

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"

//add below line 
apply plugin: 'com.google.gms.google-services'

我的andoird\build.gradle:

dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // add below line 
        classpath 'com.google.gms:google-services:4.3.3'

}

相关问题