Skip to content

flutter build framework for static library #52217

Open

Description

@lupeihong

I use 'flutter build ios-framework' to produces a framework ,but they are dynamic framewrok ,how can I produces a static framework?

Activity

  1. added
    a: existing-appsIntegration with existing apps via the add-to-app flow
    t: xcode"xcodebuild" on iOS and general Xcode project management
    toolAffects the "flutter" command-line tool. See also t: labels.
    platform-iosiOS applications specifically
    on Mar 9, 2020
  2. dnfield commented on Mar 9, 2020

    @dnfield
    Contributor
  3. jmagman commented on Mar 9, 2020

    @jmagman
    Member

    It's not possible at the moment.

    Flutter.framework is as a dylib, so providing both a dylib and static lib would involve a lot of work producing both as part of the build process, and double the size of those artifact downloads.

    Building the other frameworks statically would mean updating the Podfile to remove use_frameworks! when the command is invoked, and test with the XCFrameworks flows. You can try this manually by adding use_frameworks! to .ios/Podfile, though note that file is recreated after every flutter clean.

  4. lupeihong commented on Mar 10, 2020

    @lupeihong
    Author

    OK! THS

  5. iapicca commented on Mar 16, 2020

    @iapicca

    Hi @lupeihong @jmagman
    is this issue meant to stay open?
    Thank you

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 16, 2020
  7. jmagman commented on Apr 7, 2020

    @jmagman
    Member

    Sure, it's a valid feature request.

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 7, 2020
  9. added
    P3Issues that are less important to the Flutter project
    on Aug 18, 2020
  10. abhaysood commented on Feb 26, 2021

    @abhaysood

    Dynamic frameworks have a cost at launch time. We're evaluating integrating Flutter in a large application where it could be a deal breaker given the fact that a dynamic framework is generated for every plugin.

    Reference to official documentation which mentions limiting number of dynamically linked frameworks.
    https://developer.apple.com/documentation/xcode/improving_your_app_s_performance/reducing_your_app_s_launch_time#3323366

    It would be great if there was a way to generate static frameworks or have any other alternate approach to resolve this.

  11. jmagman commented on Feb 26, 2021

    @jmagman
    Member

    We're evaluating integrating Flutter in a large application where it could be a deal breaker given the fact that a dynamic framework is generated for every plugin.

    @abhaysood As it's written now, flutter build ios-framework generates Flutter.framework (the Flutter SDK), App.framework (your compiled dart code), pub plugins (as specified in your pubspec), and their CocoaPods dependencies (from the pub plugins's respective podspecs, if any) as dynamic frameworks. One thing you could do is to not use the generated CocoaPods frameworks, and instead use CocoaPods in your host app and add them yourself to your Podfile without the use_framework! to generate at least those as static libs.

    For example, if you were using the Flutter firebase_admob plugin, instead of embedding the generated Google-Mobile-Ads-SDK.framework you could instead add pod 'Google-Mobile-Ads-SDK' to your host app Podfile, and you would be on the hook for managing version ranges.

  12. hello-david commented on Jan 12, 2022

    @hello-david

    We're evaluating integrating Flutter in a large application where it could be a deal breaker given the fact that a dynamic framework is generated for every plugin.

    @abhaysood As it's written now, flutter build ios-framework generates Flutter.framework (the Flutter SDK), App.framework (your compiled dart code), pub plugins (as specified in your pubspec), and their CocoaPods dependencies (from the pub plugins's respective podspecs, if any) as dynamic frameworks. One thing you could do is to not use the generated CocoaPods frameworks, and instead use CocoaPods in your host app and add them yourself to your Podfile without the use_framework! to generate at least those as static libs.

    For example, if you were using the Flutter firebase_admob plugin, instead of embedding the generated Google-Mobile-Ads-SDK.framework you could instead add pod 'Google-Mobile-Ads-SDK' to your host app Podfile, and you would be on the hook for managing version ranges.

    @jmagman how about now? We very much hope that this requirement will be realized.

  13. jmagman commented on Jan 12, 2022

    @jmagman
    Member

    There's no plans to make Flutter.framework or App.framework static. For the other frameworks from CocoaPods you could follow the instructions from #52217 (comment).

  14. dvc94ch commented on Apr 3, 2022

    @dvc94ch

    I'm a bit confused. There are tons of places claiming that while dynamic libraries work on ios, they don't pass the app store review process. Does this mean that ios apps created with flutter can not be published to the app store or has this restriction been lifted?

  15. jmagman commented on Apr 4, 2022

    @jmagman
    Member

    There are tons of places claiming that while dynamic libraries work on ios, they don't pass the app store review process

    Not sure what you mean here, iOS frameworks created in Xcode by default are MACH_O_TYPE=mh_dylib, they are embedded into the app bundle and loaded as needed. I've never heard of an issue with App Store failures because the dynamic Flutter framework was embedded in the app.

  16. dvc94ch commented on Apr 4, 2022

    @dvc94ch

    after more careful reading it looks like that was before ios 8. here would be a source [0]. an additional source of confusion was rust not supporting building dynamic libraries for ios, but that seems to stem from a combination of before ios 8 times + backwards compatibility concerns [1].

  17. jmagman commented on May 25, 2022

    @jmagman
    Member

    Created a PR to add a --static flag to create just the plugins as static xcframeworks #104576. Note these still look like framework bundles, but the binaries are static libs instead of dylibs. You will only need to link these frameworks in your host app. Do not embed them in your app!

    Flutter.xcframework and App.xcframework are still dynamic libraries.

  18. jmagman commented on May 25, 2022

    @jmagman
    Member

    Created a PR to add a --static flag to create just the plugins as static xcframeworks #104576.

    This could use some docs.

  19. jmagman commented on Dec 4, 2023

    @jmagman
    Member
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: existing-appsIntegration with existing apps via the add-to-app flowplatform-iosiOS applications specificallyt: xcode"xcodebuild" on iOS and general Xcode project managementteam-iosOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions