在处理iOS时遇到了相同的错误。希望您已经使用pods安装了Firebase。您需要执行以下操作。 打开Xcode并打开AppDelegate.m文件,然后导入
#import "FIRApp.h"
[FIRApp configure];
let isFirebaseAppDefined = false;
setInterval(() => {
if (!isFirebaseAppDefined) {
if (firebase.app()) {
// Function that needs to run after the initialisation comes here
// Example re-captcha verifier or other auth function
isFirebaseAppDefined = true;
}
}
}, 100);
使用APP_INITIALIZER。
https://angular.io/api/core/APP_INITIALIZER
export function appInitializer() {
return () => firebase.initializeApp(firebaseConfig);
}
...
@NgModule({
...
providers: [{
provide: APP_INITIALIZER,
useFactory: () => appInitializer
multi: true
}]
})
export class AppModule {}
script.
function signInWithGoogle() {
firebase.initializeApp(config);
var googleAuthProvider = new firebase.auth.GoogleAuthProvider
firebase.auth().signInWithPopup(googleAuthProvider)
.then(function (data){
console.log(data)
})
.catch(function(error){
console.log(error)
})
}
步骤1:
npm install --save @react-native-firebase/app
yarn add @react-native-firebase/app
步骤2: 在 https://console.firebase.google.com/ 中生成Android凭据。 “Android包名称”必须与本地项目的包名称匹配,可以在项目中的/android/app/src/main/AndroidManifest.xml文件中的manifest标记内找到。
下载google-services.json文件并将其放置在项目的以下位置:/android/app/google-services.json。
步骤3: 然后在/ android / build.gradle文件中将google-services插件添加为依赖项: classpath 'com.google.gms:google-services:4.3.13'
最后,在/ android / app / build.gradle文件中添加以下内容以执行该插件: apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' // <- 添加此行
就这样....
const fs = require("firebase-admin");
const serviceAccount = require("../../../helper/serviceAccountKey.json");
let db = null;
// initialize firebase
if (!fs.apps.length) {
fs.initializeApp({
credential: fs.credential.cert(serviceAccount),
// name: "zippy-mvp2",
});
db = fs.firestore();
// allow undefined values.
db.settings({
ignoreUndefinedProperties: true,
});
} else {
db = fs.app().firestore();
}
在 app.module.ts 中使用 Initialize app
import { environment } from 'src/environments/environment';
firebase.initializeApp(environment.firebase);
这将清除错误。
您可以使用 firebase.database() 而不会出现任何错误。
我遇到了同样的问题。当我尝试将我的Flutter Web应用添加到Firebase时,我将Google在设置过程中给我的脚本标签复制并粘贴到了我的index.html文件中。但即使我在main方法中添加了以下行代码,这对我也没有起作用:
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());