0

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",
  );
}

1 Answer 1

1

This error has nothing to do with your app code. The error is happening at the time you build your app because the Google Services gradle plugin (the gradle plugin that reads google-serivices.json) can't work correctly without that file. Not only do you need to remove that file, but you need to remove the Google Services gradle plugin from your build.

In your Android app's build.gradle, you need to find that plugin and remove it. Looks for classpath 'com.google.gms:google-services:4.4.3(or something similar) and delete that line so that the plugin doesn't run during your build.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.