-
-
Notifications
You must be signed in to change notification settings - Fork 114
Description
Below is my full report.
This issue also happened with my Flutter app, so I created another project to double-check. 👍
👀 The possible solution is at the end of this report.
Flutter: 3.29.3 ✔️
A few dependencies for testing (all latest versions):
firebase_core: ^4.2.1
firebase_messaging: ^16.0.4
flutter_flavorizr: ^2.4.1
Flavorizr config in pubspec.yaml:
flavorizr:
ide: "vscode"
flavors:
first:
app:
name: "MyFirstWhiteLabel"
android:
applicationId: "whitelabel.first"
icon: "assets/white_labels/first/1024.jpg"
firebase:
config: "assets/white_labels/first/google-services.json"
ios:
bundleId: "whitelabel.first"
icon: "assets/white_labels/first/1024.jpg"
firebase:
config: "assets/white_labels/first/GoogleService-Info.plist"
second:
app:
name: "MySecondWhiteLabel"
android:
applicationId: "whitelabel.second"
icon: "assets/white_labels/second/1024.png"
firebase:
config: "assets/white_labels/second/google-services.json"
ios:
bundleId: "whitelabel.second"
icon: "assets/white_labels/second/1024.png"
firebase:
config: "assets/white_labels/second/GoogleService-Info.plist"
Commands I ran (the full default sequence):
flutter pub run flutter_flavorizr -p assets:download,assets:extract,android:androidManifest,android:flavorizrGradle,android:buildGradle,android:dummyAssets,android:icons,flutter:flavors,flutter:app,flutter:pages,flutter:main,ios:podfile,ios:xcconfig,ios:buildTargets,ios:schema,ios:dummyAssets,ios:icons,ios:plist,ios:launchScreen,macos:podfile,macos:xcconfig,macos:configs,macos:buildTargets,macos:schema,macos:dummyAssets,macos:icons,macos:plist,google:firebase,huawei:agconnect,assets:clean,ide:config
Here is my simple main.dart:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'app.dart';
import 'flavors.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
print("Firebase Apps length: ${Firebase.apps.length}");
await Firebase.initializeApp();
print("Firebase initialized: Apps length: ${Firebase.apps.length}");
print("App flavor: $appFlavor");
F.appFlavor = Flavor.values.firstWhere(
(element) => element.name == appFlavor,
);
print("F app flavor: ${F.appFlavor}");
runApp(const App());
}Xcode output and error:
flutter: The Dart VM service is listening on http://127.0.0.1:53666/xAp5ztKlMyM=/
flutter: Firebase Apps length: 0
flutter: Firebase initialized: Apps length: 1
flutter: App flavor: null
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Bad state: No element
#0 ListBase.firstWhere (dart:collection/list.dart:132:5)
#1 main (package:testing_flavorizr/main.dart:17:31)
<asynchronous suspension>
This error is expected ❌ because appFlavor is null.
I was able to fix the issue ✔️ by modifying the flavor/Mode xcconfig file
(example: ios/Flutter/secondDebug.xcconfig):
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
ASSET_PREFIX=second
BUNDLE_NAME=MySecondWhiteLabel
BUNDLE_DISPLAY_NAME=MySecondWhiteLabel
DART_DEFINES=$(inherited),RkxVVFRFUl9BUFBfRkxBVk9SPXNlY29uZA==
The Base64 string above is the encoded key-value pair:
FLUTTER_APP_FLAVOR=second
I’m not sure whether this is the correct fix, but after adding it I was able to build successfully. 🤔
If this is indeed the right approach, I’d be happy to submit a PR. 👍