Skip to content

"Enable Android for this project" silently fails if Android is disabled in Flutter config #3552

Closed

Description

@DanTup
  • flutter config --no-enable-android
  • Open a Flutter project without an android folder
  • Click the Device Selector and select "Enable Android for this Project"

This runs flutter create --platforms android . in the background, which completes without error but does not create the android folder and therefore appears to do nothing. Even if you switch to the Output pane to see the output, it's not clear anything went wrong:

[flutter_application_1] flutter create --platforms android --org com.dantup .
Recreating project ....
  analysis_options.yaml (created)
Running "flutter pub get" in flutter_application_1...              914ms
Wrote 1 files.

All done!
In order to run your application, type:

  $ cd .
  $ flutter run

Your application code is in ./lib/main.dart.

exit code 0

Some possible options:

  1. We run flutter config --machine and notice that Android is disabled globally and either
    a. Hide the option to enable Android
    b. Ask the user if we should enable it globally (by running flutter config --enable-android)
    c. Change "Enable Android for this project" to something more specific ("Enable Android globally and configure for this project") and automatically do (b) to enable it
  2. Change Flutter to emit an error when --platforms doesn't match any platforms when filtering out what's disabled (this would result in the error being visible to the user when they run "Enable Android for this project" because it would return an error code)

Note: We need to restart the Daemon after flutter config --enable-android is run. When the user runs it, they are shown "You may need to restart any open editors for them to read new settings" but if we're running it automatically they won't see it.

@csells any opinions on which of these you think would work best?

Activity

  1. added this to the v3.27.0 milestone on Sep 8, 2021
  2. csells commented on Sep 8, 2021

    @csells

    I think the right answer is for 'flutter create . --platforms' w/ an empty list to return an error. Ideally the VSC plugin would detect that error and offer to reset the config setting.

  3. DanTup commented on Sep 8, 2021

    @DanTup
    MemberAuthor

    I think the right answer is for flutter create . --platforms w/ an empty list to return an error

    The list isn't empty, it does have android in it, but Flutter silently doesn't create it if that's disabled globally. VS Code doesn't currently know which platforms are disabled globally, although we can use flutter config --machine to find out. I'd usually avoid reading Flutter settings like that (they feel like a detail that Flutter could change and not consider breaking), but I think it improves the UX enough here that it's worth doing (whilst having Flutter reject --platforms android when Android is disabled would prevent the error being silent, it doesn't seem like much of an improvement).

    So I'll go with 1a above - I'll leave the "Enable" option as-is, but if selected, check the platform is enabled (and if not, prompt to enable it) before running flutter create. Thanks!

  4. csells commented on Sep 8, 2021

    @csells

    sgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions