firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.64k stars 3.96k forks source link

[cli]: configuring iOS and Android apps at the same time fails due to package name and bundle id confilicts #13230

Closed diegonc closed 3 weeks ago

diegonc commented 3 weeks ago

Is there an existing issue for this?

Which plugins are affected?

App Installations

Which platforms are affected?

Android, iOS

Description

Related bug: https://github.com/firebase/flutterfire/issues/928

When running the configuration script in my app folder I'm asked for a package name to setup the android app. This value is reused as a bundle id when configuring the iOS app in the next step; which is problematic because android package names cannot contain hyphens and iOS bundle IDs cannot contain underscores.

So, let's say I have this domain for the demo app: app.ngrok-free.stirred-narwhal-formally.demo. If I use it as is, the following error is raised when creating the android app in the first step:

[info] Create your ANDROID app in project *REDACTED*:
[debug] [2024-08-28T01:11:00.254Z] >>> [apiv2][query] POST https://firebase.googleapis.com/v1beta1/projects/*REDACTED*/androidApps [none]
[debug] [2024-08-28T01:11:00.254Z] >>> [apiv2][body] POST https://firebase.googleapis.com/v1beta1/projects/*REDACTED*/androidApps {"displayName":"demo (android)","packageName":"app.ngrok-free.stirred-narwhal-formally.demo"}
[debug] [2024-08-28T01:11:00.796Z] <<< [apiv2][status] POST https://firebase.googleapis.com/v1beta1/projects/*REDACTED*/androidApps 400
[debug] [2024-08-28T01:11:00.796Z] <<< [apiv2][body] POST https://firebase.googleapis.com/v1beta1/projects/*REDACTED*/androidApps {"error":{"code":400,"message":"Request contains an invalid argument.","status":"INVALID_ARGUMENT"}}
[debug] [2024-08-28T01:11:00.797Z] HTTP Error: 400, Request contains an invalid argument.
[debug] [2024-08-28T01:11:01.200Z] FirebaseError: HTTP Error: 400, Request contains an invalid argument.
    at responseToError (C:\Users\diego\AppData\Roaming\npm\node_modules\firebase-tools\lib\responseToError.js:49:12)
    at RetryOperation._fn (C:\Users\diego\AppData\Roaming\npm\node_modules\firebase-tools\lib\apiv2.js:305:77)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[error] 
[error] Error: Failed to create Android app for project *REDACTED*

If I instead use the android friendly package name app.ngrok_free.stirred_narwhal_formally.demo, the creation of the android app succeeds but in the next step the iOS app creation fails with the following message:

[info] Create your IOS app in project *REDACTED*:
[debug] [2024-08-28T01:34:56.933Z] >>> [apiv2][query] POST https://firebase.googleapis.com/v1beta1/projects/*REDACTED*/iosApps [none]
[debug] [2024-08-28T01:34:56.933Z] >>> [apiv2][body] POST https://firebase.googleapis.com/v1beta1/projects/*REDACTE*/iosApps {"displayName":"demo (ios)","bundleId":"app.ngrok_free.stirred_narwhal_formally.demo"}
[debug] [2024-08-28T01:34:57.504Z] <<< [apiv2][status] POST https://firebase.googleapis.com/v1beta1/projects/*REDACTED*/iosApps 400
[debug] [2024-08-28T01:34:57.504Z] <<< [apiv2][body] POST https://firebase.googleapis.com/v1beta1/projects/*REDACTED*/iosApps {"error":{"code":400,"message":"Request contains an invalid argument.","status":"INVALID_ARGUMENT"}}
[debug] [2024-08-28T01:34:57.505Z] HTTP Error: 400, Request contains an invalid argument.
[debug] [2024-08-28T01:34:57.966Z] FirebaseError: HTTP Error: 400, Request contains an invalid argument.
    at responseToError (C:\Users\diego\AppData\Roaming\npm\node_modules\firebase-tools\lib\responseToError.js:49:12)
    at RetryOperation._fn (C:\Users\diego\AppData\Roaming\npm\node_modules\firebase-tools\lib\apiv2.js:305:77)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[error] 
[error] Error: Failed to create iOS app for project *REDACTED*.

Reproducing the issue

Use the flutterfire CLI tool to create a project picking both Android and iOS in the supported platforms.

The output should look somthing like below:

> flutterfire configure --project=*REDACTED*
i Found 1 Firebase projects. Selecting project *REDACTED*.
✔ Which platforms should your configuration support (use arrow keys & space to select)? · android, ios, macos, web, windows
✔ Which Android application id (or package name) do you want to use for this configuration, e.g. 'com.example.app'? · app.ngrok_free.stirred_narwhal_formally.demo
i Firebase android app app.ngrok_free.stirred_narwhal_formally.demo registered.
i Firebase ios app app.ngrok_free.stirred_narwhal_formally.demo is not registered on Firebase project *REDACTED*.
⠸ Registering new Firebase ios app on Firebase project *REDACTED*.
FirebaseCommandException: An error occured on the Firebase CLI when attempting to run a command.
COMMAND: firebase apps:create ios demo (ios) --bundle-id=app.ngrok_free.stirred_narwhal_formally.demo --json --project=*REDACTED*
ERROR: Failed to create iOS app for project *REDACTED*. See firebase-debug.log for more info.

Firebase Core version

N/A

Flutter Version

3.22.3

Relevant Log Output

No response

Flutter dependencies

Expand Flutter dependencies snippet
```yaml > flutter pub deps -- --style=compact Dart SDK 3.4.4 Flutter SDK 3.22.3 alertas 1.0.0+1 dependencies: - app_links 6.3.0 [flutter app_links_linux app_links_platform_interface app_links_web] - cupertino_icons 1.0.8 - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_map 7.0.2 [async collection dart_earcut flutter http latlong2 logger meta polylabel proj4dart vector_math] - flutter_map_location_marker 9.0.0 [flutter flutter_compass flutter_map geolocator latlong2] - flutter_spinkit 5.2.1 [flutter] - geolocator 12.0.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows] - get 4.6.6 [flutter] - intl 0.19.0 [clock meta path] - latlong2 0.9.1 [intl] - supabase_flutter 2.6.0 [app_links async crypto flutter http meta supabase url_launcher path_provider shared_preferences] dev dependencies: - flutter_lints 3.0.2 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service] transitive dependencies: - app_links_linux 1.0.3 [flutter app_links_platform_interface gtk] - app_links_platform_interface 2.0.2 [flutter plugin_platform_interface] - app_links_web 1.0.4 [flutter flutter_web_plugins app_links_platform_interface web] - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - characters 1.3.0 - clock 1.1.1 - collection 1.18.0 - crypto 3.0.4 [typed_data] - dart_earcut 1.1.0 - fake_async 1.3.1 [clock collection] - ffi 2.1.3 - file 7.0.0 [meta path] - fixnum 1.1.0 - flutter_compass 0.8.0 [flutter] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math] - functions_client 2.3.2 [http yet_another_json_isolate] - geolocator_android 4.6.1 [flutter geolocator_platform_interface meta uuid] - geolocator_apple 2.3.7 [flutter geolocator_platform_interface] - geolocator_platform_interface 4.2.4 [flutter plugin_platform_interface vector_math meta] - geolocator_web 4.1.1 [flutter flutter_web_plugins geolocator_platform_interface web] - geolocator_windows 0.2.3 [flutter geolocator_platform_interface] - gotrue 2.8.4 [collection crypto http jwt_decode retry rxdart meta] - gtk 2.1.0 [ffi flutter meta] - http 1.2.2 [async http_parser meta web] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - jwt_decode 0.3.1 - leak_tracker 10.0.4 [clock collection meta path vm_service] - leak_tracker_flutter_testing 3.0.3 [flutter leak_tracker leak_tracker_testing matcher meta] - leak_tracker_testing 3.0.1 [leak_tracker matcher meta] - lints 3.0.0 - lists 1.0.1 [meta] - logger 2.4.0 - matcher 0.12.16+1 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.8.0 [collection] - meta 1.12.0 - mgrs_dart 2.0.0 [unicode] - mime 1.0.5 - path 1.9.0 - path_provider 2.1.4 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - path_provider_android 2.2.10 [flutter path_provider_platform_interface] - path_provider_foundation 2.4.0 [flutter path_provider_platform_interface] - path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface] - path_provider_windows 2.3.0 [ffi flutter path path_provider_platform_interface] - platform 3.1.5 - plugin_platform_interface 2.1.8 [meta] - polylabel 1.0.1 [collection] - postgrest 2.1.4 [http yet_another_json_isolate meta] - proj4dart 2.1.0 [mgrs_dart wkt_parser meta] - realtime_client 2.2.1 [collection http meta web_socket_channel] - retry 3.1.2 - rxdart 0.28.0 - shared_preferences 2.3.1 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shared_preferences_android 2.3.1 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.5.2 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.4.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.4.1 [flutter plugin_platform_interface] - shared_preferences_web 2.4.2 [flutter flutter_web_plugins shared_preferences_platform_interface web] - shared_preferences_windows 2.4.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - sprintf 7.0.0 - stack_trace 1.11.1 [path] - storage_client 2.0.3 [http http_parser mime retry meta] - stream_channel 2.1.2 [async] - string_scanner 1.2.0 [source_span] - supabase 2.3.0 [functions_client gotrue http postgrest realtime_client storage_client rxdart yet_another_json_isolate] - term_glyph 1.2.1 - test_api 0.7.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - typed_data 1.3.2 [collection] - unicode 0.3.1 [lists] - url_launcher 6.3.0 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - url_launcher_android 6.3.9 [flutter url_launcher_platform_interface] - url_launcher_ios 6.3.1 [flutter url_launcher_platform_interface] - url_launcher_linux 3.2.0 [flutter url_launcher_platform_interface] - url_launcher_macos 3.2.0 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface] - url_launcher_web 2.3.3 [flutter flutter_web_plugins url_launcher_platform_interface web] - url_launcher_windows 3.1.2 [flutter url_launcher_platform_interface] - uuid 4.4.2 [crypto sprintf meta fixnum] - vector_math 2.1.4 - vm_service 14.2.1 - web 1.0.0 - web_socket 0.1.6 [web] - web_socket_channel 3.0.1 [async crypto stream_channel web web_socket] - wkt_parser 2.0.0 - xdg_directories 1.0.4 [meta path] - yet_another_json_isolate 2.0.2 [async] ```

Additional context and comments

As a spin-off issue, on windows flutterfire cli stops reading if the console window's width is too small to fit the answer to one of the question (specifically the domain, as you can see from the logs it's quite long).

Back to the current issue, as a workaround, I guess I could try to create of the iOS app from the Firebase console and then rerun the command. Existing app seem to be picked without issue by the CLI.

PD: Giving it a second thought, the proposed workaround may not work becase the CLI will still lookup the android package instead of the manually corrected bundle ID. I'd have to try...

PD2: Another workaround I may try is to run the CLI as many times as there are varying inputs, but I don't trust a compounded configuration would be created in such case. Again, I'd have to try.

SelaseKay commented 3 weeks ago

Hi @diegonc . Thanks for the report. I'm unable to reproduce this on my end. flutterfire configure does not reuse the android application id in my case. Can you check the value of PRODUCT_BUNDLE_IDENTIFIER located at ios/Runner.xcodeproj/project.pbxproj? This value is normally used as the bundle ID when configuring iOS apps for firebase.

diegonc commented 3 weeks ago

Ah, you are right. I had the underscored version of the domain in iOS and macOS configuration files.

I guess this could be either closed or rebranded to the spin-off bug report

As a spin-off issue, on Windows flutterfire cli stops reading if the console window's width is too small to fit the answer to one of the question (specifically the domain, as you can see from the logs it's quite long).

SelaseKay commented 3 weeks ago

I'll go ahead and close this issue. You can open a new issue regarding the Windows flutterfire cli.