Skip to content

Support flavors for Windows #98994

Closed

Description

@krll-kov

Steps to reproduce:

  • Create new Flutter project on Windows
  • Go to windows/CMakeLists.txt and replace
set(BINARY_NAME "tesee1")

with

set(APPLICATION_TYPE 0)
add_compile_definitions(IS_EXLOADER=${APPLICATION_TYPE})

if(APPLICATION_TYPE)
  set(BINARY_NAME "tesee1")
else()
  set(BINARY_NAME "example2")
endif()
  • Start application(clean build folder if you've compiled app before)

For some reason flutter creates .exe file with filename example2 but tries to start tesee1
image

Flutter version: 2.10.2 from stable channel

Activity

  1. stuartmorgan-g commented on Feb 23, 2022

    @stuartmorgan-g
    Contributor

    The flutter tool is just using a simple pattern match to extract the name of the binary to launch; it doesn't know anything about CMake logic. So the changes you have made break the tool's ability to know what the application you are building is called.

    What are you trying to accomplish here?

  2. krll-kov commented on Feb 23, 2022

    @krll-kov
    ContributorAuthor

    BINARY_NAME

    image
    Yet BINARY_NAME is the recommended way of changing the name of the generated binary.

    What i'm trying to achieve is one code base with two whole different UI implementations. Just switch one variable in CMake and app will be rendered differently

  3. stuartmorgan-g commented on Feb 23, 2022

    @stuartmorgan-g
    Contributor

    Yet BINARY_NAME is the recommended way of changing the name of the generated binary.

    Yes, it is. Specifically, by changing the value (the comment says "Change this line" not "Add arbitrary logic around this line").

    The Flutter tool doesn't support all possible changes to the native build files, on any platform. If you change things that Flutter relies on, the tool can't drive it correctly any more.

    What i'm trying to achieve is one code base with two whole different UI implementations. Just switch one variable in CMake and app will be rendered differently

    It sounds like you want flavor support for Windows; updating description accordingly.

  4. added
    platform-windowsBuilding on or for Windows specifically
    c: new featureNothing broken; request for a new capability
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Feb 23, 2022
  5. changed the title [-]Windows CMakeLists.txt BINARY_NAME issue[/-] [+]Support flavors for Windows[/+] on Feb 23, 2022
  6. krll-kov commented on Feb 23, 2022

    @krll-kov
    ContributorAuthor

    flavor support for Windows

    I do not know what is flavor, just to avoid unnecessary renames every build i tried to implement dynamic executable name

  7. added
    P3Issues that are less important to the Flutter project
    on Mar 3, 2022
  8. cybrox commented on Feb 24, 2023

    @cybrox

    @Kirill-21 This is exactly what flavors would allow you to do.

    They would allow you to specify different names, build settings, icons, etc. depending on the flavor (what you call APPLICATION_TYPE.


    On topic: I would really like flavor support on Windows as well. When someone tackles this, it'd be great to have the current flavor exposed to CMakeLists as a variable or environment variable as well. This would allow adding necessary custom logic to the end of the file so people don't have to mess with the rest.

  9. insertjokehere commented on Aug 29, 2023

    @insertjokehere

    This is something I'm very interested in as well. For a first pass, would it make sense to modify the generated CMake config here:

    final StringBuffer buffer = StringBuffer('''
    # Generated code do not commit.
    file(TO_CMAKE_PATH "$escapedFlutterRoot" FLUTTER_ROOT)
    file(TO_CMAKE_PATH "$escapedProjectDir" PROJECT_DIR)
    set(FLUTTER_VERSION "$version" PARENT_SCOPE)
    set(FLUTTER_VERSION_MAJOR ${version.major} PARENT_SCOPE)
    set(FLUTTER_VERSION_MINOR ${version.minor} PARENT_SCOPE)
    set(FLUTTER_VERSION_PATCH ${version.patch} PARENT_SCOPE)
    set(FLUTTER_VERSION_BUILD ${buildVersion ?? 0} PARENT_SCOPE)
    # Environment variables to pass to tool_backend.sh
    list(APPEND FLUTTER_TOOL_ENVIRONMENT
    "FLUTTER_ROOT=$escapedFlutterRoot"
    "PROJECT_DIR=$escapedProjectDir"
    ''');
    environment.forEach((String key, String value) {
    final String configValue = _escapeBackslashes(value);
    buffer.writeln(' "$key=$configValue"');
    });
    buffer.writeln(')');
    project.generatedCmakeConfigFile
    ..createSync(recursive: true)
    ..writeAsStringSync(buffer.toString());
    }

    To set a FLUTTER_BUILD_FLAVOR variable (using the value passed in by the BuildInfo object) that could be referenced in the other CMake files to do whatever conditional logic you need for your different flavors. In our case this is picking a different icon, linking in a different resource file, and copying different public keys into the install directory.

    You'd also need to modify

    BuildWindowsCommand({
    required super.logger,
    bool verboseHelp = false,
    }) : super(verboseHelp: verboseHelp) {
    addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
    }

    To call usesFlavorOption() similar to how build_appbundle.dart does it.

    I'm happy to spend a bit of time putting together a PR for this, but before I do can someone from the desktop team speak to if a design like this would be acceptable?

  10. 4 remaining items

  11. talamaska commented on Apr 25, 2024

    @talamaska
  12. added
    team-windowsOwned by the Windows platform team
    and removed on Jun 6, 2024
  13. flutter-triage-bot commented on Jun 6, 2024

    @flutter-triage-bot
  14. Stumblinbear commented on Jun 17, 2024

    @Stumblinbear
  15. 12people commented on Jan 29, 2025

    @12people

    I created a corresponding ticket for Linux, so that all desktop platforms can have equal flavor support.

  16. kjxbyz commented on Jan 29, 2025

    @kjxbyz
  17. lucavenir commented on May 4, 2026

    @lucavenir
  18. added a commit that references this issue on Jun 29, 2026
    0145a67
  19. github-actions commented on Jul 14, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  20. locked as resolved and limited conversation to collaborators on Jul 14, 2026
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

    P3Issues that are less important to the Flutter projecta: desktopRunning on desktopc: new featureNothing broken; request for a new capabilityplatform-windowsBuilding on or for Windows specificallyteam-windowsOwned by the Windows platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-windowsTriaged by the Windows platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions