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]: Flutter build ipa fails with FirebaseJsonException in project with multiple flavors. #354

Closed
1 task done
Leedwon opened this issue Jan 13, 2025 · 6 comments
Closed
1 task done
Labels
bug Something isn't working Needs Attention OP created or responded to issue and it needs attention.

Comments

@Leedwon
Copy link

Leedwon commented Jan 13, 2025

Is there an existing issue for this?

  • I have searched the existing issues.

CLI Version

1.0.0

Firebase Tools version

13.29.0

Flutter Doctor Output

[✓] Flutter (Channel stable, 3.24.5, on macOS 14.6.1 23G93 darwin-arm64, locale
    en-PL)
    • Flutter version 3.24.5 on channel stable at /Users/jakubledwon/Dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision dec2ee5c1f (9 weeks ago), 2024-11-13 11:13:06 -0800
    • Engine revision a18df97ca5
    • Dart version 3.5.4
    • DevTools version 2.37.3

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/jakubledwon/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor
      --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version unknown)
    • Android Studio at /Applications/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to determine Android Studio version.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] Android Studio (version 2024.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] IntelliJ IDEA Community Edition (version 2024.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.96.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   •
      macOS 14.6.1 23G93 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         •
      macOS 14.6.1 23G93 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript •
      Google Chrome 131.0.6778.265
    ! Error: Browsing on the local area network for iPhone 13 mini. Ensure the
      device is unlocked and attached with a cable or associated with the same
      local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code
      -27)

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Description

When trying to produce an Xcode archive by running flutter build ipa --flavor prod -t lib/main_prod.dart it fails with:

FirebaseJsonException: Please run "flutterfire configure" to update the firebase.json at the root of your Flutter project with correct values.

Re-running flutterfire configure doesn't solve the issue.

In my setup I have three flavors:

  • local
  • dev
  • prod

For each flavor I have Scheme with the same name, and corresponding build configurations:

  • Debug-local
  • Debug-dev
  • Debug-prod
  • Release-local
  • Release-dev
  • Release-prod
  • Profile-local
  • Profile-dev
  • Profile-prod

Each flavors has its own corresponding firebase project:

  • myapp-local
  • myapp-dev
  • myapp (for prod)

I checked my schemes and configs as suggested in this issue, but I can't spot any issues with my configuration. Moreover running flutter run --flavor prod -t lib/main_prod.dart works without any issues.

I'm using a custom script for configuring flutterfire which looks like this:

#!/bin/bash
# Script to generate Firebase configuration files for different environments/flavors

if [[ $# -eq 0 ]]; then
  echo "Error: No environment specified. Use 'local', 'dev', or 'prod'."
  exit 1
fi

case $1 in
  local)
    flutterfire config \
      --project=myproject-local \
      --out=lib/firebase_options_local.dart \
      --ios-bundle-id=myapp.local \
      --ios-out=ios/flavors/local/GoogleService-Info.plist \
      --android-package-name=myapp.local \
      --android-out=android/app/src/local/google-services.json
    ;;
  dev)
    flutterfire config \
      --project=myproject-dev \
      --out=lib/firebase_options_dev.dart \
      --ios-bundle-id=myapp.dev \
      --ios-out=ios/flavors/dev/GoogleService-Info.plist \
      --android-package-name=myapp.dev \
      --android-out=android/app/src/dev/google-services.json
    ;;
  prod)
    flutterfire config \
      --project=myapp \
      --out=lib/firebase_options_prod.dart \
      --ios-bundle-id=myapp \
      --ios-out=ios/flavors/prod/GoogleService-Info.plist \
      --android-package-name=myapp \
      --android-out=android/app/src/prod/google-services.json
    ;;
  *)
    echo "Error: Invalid environment specified. Use 'local', 'dev', or 'prod'."
    exit 1
    ;;
esac

Is there any way I could examine this FirebaseJsonException to see what exactly can't be parsed

Steps to reproduce

I haven't tried creating a MRE, but I assume the steps would be:

  • Create a sample flutter app
  • Create three schemes: local,dev,prod
  • Create build configs for each of them and remove default build configs
  • Create firebase projects for each flavor
  • Use custom script from description to configure each flavor firebase setup
  • Run flutter build ipa --flavor prod to observe the issue

Expected behavior

Flutter build ipa succeeds without any issues

Screenshots

No response

Additional context and comments

My current firebase.json looks like this:

{
    "flutter": {
        "platforms": {
            "android": {
                "buildConfigurations": {
                    "src/dev": {
                        "projectId": "myapp-dev-3892d",
                        "appId": "redacted",
                        "fileOutput": "android/app/src/dev/google-services.json"
                    },
                    "src/prod": {
                        "projectId": "myapp",
                        "appId": "redacted",
                        "fileOutput": "android/app/src/prod/google-services.json"
                    },
                    "src/local": {
                        "projectId": "myapp-local",
                        "appId": "redacted",
                        "fileOutput": "android/app/src/local/google-services.json"
                    }
                }
            },
            "ios": {
                "buildConfigurations": {
                    "Debug-dev": {
                        "projectId": "myapp-dev-3892d",
                        "appId": "redacted",
                        "uploadDebugSymbols": true,
                        "fileOutput": "ios/flavors/dev/GoogleService-Info.plist"
                    },
                    "Debug-prod": {
                        "projectId": "myapp",
                        "appId": "redacted",
                        "uploadDebugSymbols": true,
                        "fileOutput": "ios/flavors/prod/GoogleService-Info.plist"
                    },
                    "Debug-local": {
                        "projectId": "myapp-local",
                        "appId": "redacted",
                        "uploadDebugSymbols": true,
                        "fileOutput": "ios/flavors/local/GoogleService-Info.plist"
                    }
                }
            },
            "dart": {
                "lib/firebase_options_dev.dart": {
                    "projectId": "myapp-dev-3892d",
                    "configurations": {
                        "android": "redacted",
                        "ios": "redacted"
                    }
                },
                "lib/firebase_options_prod.dart": {
                    "projectId": "myapp",
                    "configurations": {
                        "android": "redacted",
                        "ios": "redacted"
                    }
                },
                "lib/firebase_options_local.dart": {
                    "projectId": "myapp-local",
                    "configurations": {
                        "android": "redacted",
                        "ios": "redacted"
                    }
                }
            }
        }
    }
}
@russellwheatley
Copy link
Member

Hey @Leedwon - I've just cut another release. If you want to install the latest version:

dart pub global activate flutterfire_cli

It should print out the problem with your firebase.json file. Let me know how it goes 👍

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

Leedwon commented Jan 13, 2025

Hi @russellwheatley, thanks for the super quick improvements. I performed the following steps:

  • run dart pub global activate flutterfire_cli
  • checked flutterfire --version - it's 1.0.1 (It was 1.0.0 so I think your improvement is there)
  • run flutter clean to ensure the plugin is up to date
  • run flutter build ipa --no-tree-shake-icons --flavor dev --dart-define-from-file="dev_config.json" -t lib/main_dev.dart to trigger the exception
  • got the same exception, but weirdly I don't see the underlyingException:

Still got:

FirebaseJsonException: Please run "flutterfire configure" to update the firebase.json at the root of your Flutter project with correct values.

To add some more context I can see: Command PhaseScriptExecution failed with a nonzero exit code, so it probably fails at the FlutterFire script added in BuildPhases (I assume)

I also tried running flutterfire_cli with your fix locally, I saw:

You are running a local development version of FlutterFire CLI.

when running flutterfire --version, but didn't see underlyingException either

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

Leedwon commented Jan 13, 2025

I can see that there is the following line:

if (projectId == null || appId == null) {
    throw FirebaseJsonException();
}

In the upload_symbols.dart perhaps that's the issue

@Leedwon
Copy link
Author

Leedwon commented Jan 13, 2025

I managed to spot the issue in my firebase.json. The problem was that I only run ./scripts/flutterfire-config.sh for Debug-flavor configuration (Debug-dev, Debug-prod etc.) I should've also run it for Release-flavor configurations. After running this script for the Release-flavor configurations issue is gone. I think the one minor improvement that could be done is to add some error message to the:

if (projectId == null || appId == null) {
    throw FirebaseJsonException();
}

i.e projectId or appId not found in firebase.json for config :$buildConfiguration. If you think it's worth it I could try opening PR with such change, as for this issue I think we could close it 🙂

@russellwheatley
Copy link
Member

Hey @Leedwon - that's wonderful news, glad it helped spot the issue. If you wanted to open a PR for the above noted, I would help shepherd it through 😄

@Leedwon
Copy link
Author

Leedwon commented Jan 15, 2025

That would be awesome, I will try to do it later this week or at the beginning of next week

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