I am building an a Flutter app for Android, iOS and the web.
I want to be able to very easily change between firebase projects. My plan was to manually provide the firebase credentials to the app at initialization.
I have done this, in the following file I created.
I am providing firebase all the info it needs to initialize, and it should not require the google-services.json. I have therefore deleted the google-service.json. But upon building the app I get the following exception...
What went wrong: Execution failed for task ':app:processDebugGoogleServices'. File google-services.json is missing. The Google Services Plugin cannot function without it.
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform, kDebugMode;
class FirebaseOptionManager {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
return kDebugMode ? webDev : webProd;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return kDebugMode ? androidDev : androidProd;
case TargetPlatform.iOS:
return kDebugMode ? iosDev : iosProd;
case TargetPlatform.macOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for macos - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.windows:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for windows - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}
static const FirebaseOptions androidDev = FirebaseOptions(
apiKey: 'REDACTED_API_KEY_ANDROID_DEV',
appId: '1:REDACTED_PROJECT_NUMBER:android:REDACTED_APP_ID',
messagingSenderId: 'REDACTED_SENDER_ID',
projectId: 'your-project-dev',
storageBucket: 'your-project-dev.firebasestorage.app',
);
static const FirebaseOptions iosDev = FirebaseOptions(
apiKey: 'REDACTED_API_KEY_IOS_DEV',
appId: '1:REDACTED_PROJECT_NUMBER:ios:REDACTED_APP_ID',
messagingSenderId: 'REDACTED_SENDER_ID',
projectId: 'your-project-dev',
storageBucket: 'your-project-dev.firebasestorage.app',
iosBundleId: 'com.yourcompany.yourapp',
iosClientId: 'REDACTED_CLIENT_ID.apps.googleusercontent.com',
);
static const webDev = FirebaseOptions(
apiKey: "REDACTED_API_KEY_WEB_DEV",
authDomain: "your-project-dev.firebaseapp.com",
projectId: "your-project-dev",
storageBucket: "your-project-dev.firebasestorage.app",
messagingSenderId: "REDACTED_SENDER_ID",
appId: "1:REDACTED_PROJECT_NUMBER:web:REDACTED_APP_ID",
);
static const FirebaseOptions androidProd = FirebaseOptions(
apiKey: 'REDACTED_API_KEY_ANDROID_PROD',
appId: '1:REDACTED_PROJECT_NUMBER:android:REDACTED_APP_ID',
messagingSenderId: 'REDACTED_SENDER_ID',
projectId: 'your-project-prod',
storageBucket: 'your-project-prod.firebasestorage.app',
);
static const FirebaseOptions iosProd = FirebaseOptions(
apiKey: 'REDACTED_API_KEY_IOS_PROD',
appId: '1:REDACTED_PROJECT_NUMBER:ios:REDACTED_APP_ID',
messagingSenderId: 'REDACTED_SENDER_ID',
projectId: 'your-project-prod',
storageBucket: 'your-project-prod.firebasestorage.app',
iosBundleId: 'com.yourcompany.yourapp',
iosClientId: 'REDACTED_CLIENT_ID.apps.googleusercontent.com',
);
static const webProd = FirebaseOptions(
apiKey: "REDACTED_API_KEY_WEB_PROD",
projectId: "your-project-prod",
storageBucket: "your-project-prod.firebasestorage.app",
messagingSenderId: "REDACTED_SENDER_ID",
appId: "1:REDACTED_PROJECT_NUMBER:web:REDACTED_APP_ID",
authDomain: "your-project-prod.firebaseapp.com",
);
}