Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: Failed to write android google-services.json file on CI when using flutterfire reconfigure #365

Open
1 task done
AhmedLSayed9 opened this issue Jan 17, 2025 · 12 comments
Labels
bug Something isn't working Needs Attention OP created or responded to issue and it needs attention.

Comments

@AhmedLSayed9
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues.

CLI Version

1.0.1

Firebase Tools version

13.29.1

Flutter Doctor Output

[✓] Flutter (Channel stable, 3.24.3, on macOS 15.2 24C101 darwin-arm64, locale en-EG)
• Flutter version 3.24.3 on channel stable at /Users/ahmedelsayed/.puro/envs/locals/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2663184aa7 (4 months ago), 2024-09-11 16:27:48 -0500
• Engine revision 36335019a8
• Dart version 3.5.3
• DevTools version 2.37.3

Description

When using Firebase service account JSON file and use flutterfire reconfigure instead of flutterfire configure on CI, it fails.

This was requested before at #232

Steps to reproduce

Add Firebase service account JSON to your secrets and try running the following on CI:

  • name: Add Firebase service account credentials files
    env:
    FIREBASE_SERVICE_ACCOUNT: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
    run: |
    echo $FIREBASE_SERVICE_ACCOUNT > /tmp/google-application-credentials.json
  • name: Configure Firebase
    env:
    GOOGLE_APPLICATION_CREDENTIALS: /tmp/google-application-credentials.json
    run: flutterfire configure ...... // Complete your project configurations

It should run successfully, but If you use flutterfire reconfigure, it'll fail with the following error:

Failed to write android google-services.json file write for build configuration: "src/dev". Please report this issue at:https://github.com/invertase/flutterfire_cli. Exception: type 'Null' is not a subtype of type 'Map<String, dynamic>' in type cast

Expected behavior

I expect flutterfire reconfigure to work on CI.

Screenshots

No response

Additional context and comments

No response

@AhmedLSayed9 AhmedLSayed9 added bug Something isn't working triage labels Jan 17, 2025
@russellwheatley
Copy link
Member

@AhmedLSayed9 - Is there a stack trace to go with it?

What does your firebase.json look like for android, specifically for this build configuration src/dev. Redact any sensitive strings, only concerned with structure.

@russellwheatley russellwheatley added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed triage labels Jan 24, 2025
@github-actions github-actions bot added the Needs Attention OP created or responded to issue and it needs attention. label Jan 24, 2025
@AhmedLSayed9
Copy link
Contributor Author

What does your firebase.json look like for android, specifically for this build configuration src/dev. Redact any sensitive strings, only concerned with structure.

{
  "flutter": {
    "platforms": {
      "android": {
        "buildConfigurations": {
          "src/dev": {
            "projectId": "REDACTED_PROJECT_ID",
            "appId": "REDACTED_APP_ID",
            "fileOutput": "android/app/src/dev/google-services.json"
          },
          "src/staging": {
            "projectId": "REDACTED_PROJECT_ID",
            "appId": "REDACTED_APP_ID",
            "fileOutput": "android/app/src/staging/google-services.json"
          },
          "src/prod": {
            "projectId": "REDACTED_PROJECT_ID_PRODUCTION",
            "appId": "REDACTED_APP_ID_PRODUCTION",
            "fileOutput": "android/app/src/prod/google-services.json"
          }
        }
      },
      "ios": {
        "buildConfigurations": {
          "Debug-dev": {
            "projectId": "REDACTED_PROJECT_ID",
            "appId": "REDACTED_APP_ID",
            "uploadDebugSymbols": true,
            "fileOutput": "ios/config/dev/GoogleService-Info.plist"
          },
          "Profile-dev": {
            "projectId": "REDACTED_PROJECT_ID",
            "appId": "REDACTED_APP_ID",
            "uploadDebugSymbols": true,
            "fileOutput": "ios/config/dev/GoogleService-Info.plist"
          },
          "Release-dev": {
            "projectId": "REDACTED_PROJECT_ID",
            "appId": "REDACTED_APP_ID",
            "uploadDebugSymbols": true,
            "fileOutput": "ios/config/dev/GoogleService-Info.plist"
          },
          "Debug-staging": {
            "projectId": "REDACTED_PROJECT_ID",
            "appId": "REDACTED_APP_ID",
            "uploadDebugSymbols": true,
            "fileOutput": "ios/config/staging/GoogleService-Info.plist"
          },
          "Profile-staging": {
            "projectId": "REDACTED_PROJECT_ID",
            "appId": "REDACTED_APP_ID",
            "uploadDebugSymbols": true,
            "fileOutput": "ios/config/staging/GoogleService-Info.plist"
          },
          "Release-staging": {
            "projectId": "REDACTED_PROJECT_ID",
            "appId": "REDACTED_APP_ID",
            "uploadDebugSymbols": true,
            "fileOutput": "ios/config/staging/GoogleService-Info.plist"
          },
          "Debug-prod": {
            "projectId": "REDACTED_PROJECT_ID_PRODUCTION",
            "appId": "REDACTED_APP_ID_PRODUCTION",
            "uploadDebugSymbols": true,
            "fileOutput": "ios/config/prod/GoogleService-Info.plist"
          },
          "Profile-prod": {
            "projectId": "REDACTED_PROJECT_ID_PRODUCTION",
            "appId": "REDACTED_APP_ID_PRODUCTION",
            "uploadDebugSymbols": true,
            "fileOutput": "ios/config/prod/GoogleService-Info.plist"
          },
          "Release-prod": {
            "projectId": "REDACTED_PROJECT_ID_PRODUCTION",
            "appId": "REDACTED_APP_ID_PRODUCTION",
            "uploadDebugSymbols": true,
            "fileOutput": "ios/config/prod/GoogleService-Info.plist"
          }
        }
      },
      "dart": {
        "lib/firebase_options_dev.dart": {
          "projectId": "REDACTED_PROJECT_ID",
          "configurations": {
            "android": "REDACTED_APP_ID",
            "ios": "REDACTED_APP_ID"
          }
        },
        "lib/firebase_options_staging.dart": {
          "projectId": "REDACTED_PROJECT_ID",
          "configurations": {
            "android": "REDACTED_APP_ID",
            "ios": "REDACTED_APP_ID"
          }
        },
        "lib/firebase_options_prod.dart": {
          "projectId": "REDACTED_PROJECT_ID_PRODUCTION",
          "configurations": {
            "android": "REDACTED_APP_ID_PRODUCTION",
            "ios": "REDACTED_APP_ID_PRODUCTION"
          }
        }
      }
    }
  }
}

@github-actions github-actions bot removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jan 24, 2025
@AhmedLSayed9
Copy link
Contributor Author

Image

@russellwheatley
Copy link
Member

Have you reproducing locally?

It's going to be one of these if it is android I think:

https://github.com/invertase/flutterfire_cli/blob/main/packages/flutterfire_cli/lib/src/commands/reconfigure.dart#L393
https://github.com/invertase/flutterfire_cli/blob/main/packages/flutterfire_cli/lib/src/commands/reconfigure.dart#L415

Is the firebase.json in the root of the project?

The firebase.json configuration seems correct to me. A local repro would be helpful.

@russellwheatley russellwheatley added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention OP created or responded to issue and it needs attention. labels Jan 24, 2025
@github-actions github-actions bot added the Needs Attention OP created or responded to issue and it needs attention. label Jan 24, 2025
@AhmedLSayed9
Copy link
Contributor Author

flutterfire reconfigure works fine locally

@github-actions github-actions bot removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jan 24, 2025
@AhmedLSayed9
Copy link
Contributor Author

The difference is locally I'm logged in using firebase login but at the CI I'm using firebase service account credentials.

@AhmedLSayed9
Copy link
Contributor Author

Is the firebase.json in the root of the project?

Yes

@russellwheatley
Copy link
Member

The difference is locally I'm logged in using firebase login but at the CI I'm using firebase service account credentials.

I don't think this should make a difference. Not sure what the problem is, It's saying something that is expected to be a map (from those lines I pasted earlier), is null.

You ought to put some debug logs on firebase.json path, content, etc to find out why map is empty. It's clearly a difference between your CI and local environment.

@russellwheatley russellwheatley added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention OP created or responded to issue and it needs attention. labels Jan 24, 2025
@github-actions github-actions bot added the Needs Attention OP created or responded to issue and it needs attention. label Jan 24, 2025
@AhmedLSayed9
Copy link
Contributor Author

@russellwheatley

I was able to reproduce it using a minimal sample: https://github.com/AhmedLSayed9/firebase_test

Check the workflow: https://github.com/AhmedLSayed9/firebase_test/actions/runs/12951734235/job/36127428141

To reproduce:

  1. Clone the repo, add a firebase project to it and update firebase.json file.
  2. Add an environment secret to your repo that includes the service account json with the name FIREBASE_SERVICE_ACCOUNT.
  3. Update --project=test-c7826 at .github/workflows/build.yml to your project id.
  4. Try running the CI workflow

@github-actions github-actions bot removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jan 24, 2025
@russellwheatley
Copy link
Member

@AhmedLSayed9 - the problem is; even if I can reproduce this on your CI, I still wouldn't know the root cause until I can reproduce locally. Like I said:

You ought to put some debug logs on firebase.json path, content, etc to find out why map is empty. It's clearly a difference between your CI and local environment.

If you find the root cause or find a way to reproduce locally, I can fix the problem.

@AhmedLSayed9
Copy link
Contributor Author

@russellwheatley

I was able to reproduce it locally, steps:

  1. Clone/Download the repo, add a firebase project to it and update firebase.json file to yours.
  2. Download your Firebase service account json file and add it to the project directory.
  3. Run the following commands at the project directory:
    firebase logout
    
    export GOOGLE_APPLICATION_CREDENTIALS="your-file-name.json"
    
  4. Test the following command:
    firebase projects:list --debug
    
    Result (Succeed):
    [2025-02-03T22:21:40.483Z] Object "" in "firebase.json" has unknown property: {"additionalProperty":"flutter"}
    (node:10956) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    (Use `node --trace-deprecation ...` to show where the warning was created)
    [2025-02-03T22:21:40.486Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
    [2025-02-03T22:21:40.806Z] Running auto auth
    ⠋ Preparing the list of your Firebase projects[2025-02-03T22:21:40.810Z] No OAuth tokens found
    [2025-02-03T22:21:40.812Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects pageSize=1000
    ⠧ Preparing the list of your Firebase projects[2025-02-03T22:21:41.418Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects 200
    [2025-02-03T22:21:41.418Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects [omitted]
    ✔ Preparing the list of your Firebase projects
    ┌──────────────────────┬────────────┬────────────────┬──────────────────────┐
    │ Project Display Name │ Project ID │ Project Number │ Resource Location ID │
    ├──────────────────────┼────────────┼────────────────┼──────────────────────┤
    │ test                 │ test-c7826 │ 833909521065   │ [Not specified]      │
    └──────────────────────┴────────────┴────────────────┴──────────────────────┘
    
    1 project(s) total.
    
  5. Test the following command (Replace test-c7826 with your project id):
    flutterfire config --project=test-c7826 --platforms=android,ios --out=lib/firebase_options.dart --overwrite-firebase-options --yes
    
    Result (Succeed):
    i Found 1 Firebase projects. Selecting project test-c7826.                                                                                                                                
    i Selected platforms: android,ios
    i Firebase android app com.example.firebase_test registered.                                                                                                                              
    i Firebase ios app com.example.firebaseTest registered.                                                                                                                                   
    
    Firebase configuration file lib/firebase_options.dart generated successfully with the following Firebase apps:
    
    Platform  Firebase App Id
    android   1:833909521065:android:30256bc9f08203c4ab87b8
    ios       1:833909521065:ios:1e3526ad7d1078a4ab87b8
    
    Learn more about using this file and next steps from the documentation:
     > https://firebase.google.com/docs/flutter/setup
    
  6. Test the following command:
    flutterfire reconfigure
    
    Result (Failed):
    Failed to write android google-services.json file write for default service file. Please report this issue at:https://github.com/invertase/flutterfire_cli. Exception: type 'Null' is not a subtype of type 'Map<String, dynamic>' in type cast
    type 'Null' is not a subtype of type 'Map<String, dynamic>' in type cast
    

Let me know If you need more information.

@russellwheatley
Copy link
Member

@AhmedLSayed9 - thank you, I will get round to fixing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Needs Attention OP created or responded to issue and it needs attention.
Projects
None yet
Development

No branches or pull requests

2 participants