Skip to content

Support app clips on iOS 14 #60029

Closed
flutter/website
#4592

Description

@xster

We'll want more details from https://developer.apple.com/videos/play/wwdc2020/10174/. So far, it seems like it's just a separate build target in Xcode and you choose which target your sources get compiled into. Hopefully that includes selection for frameworks too.

Activity

  1. added
    platform-iosiOS applications specifically
    engineflutter/engine related. See also e: labels.
    on Jun 22, 2020
  2. edeuss commented on Jun 22, 2020

    @edeuss

    Would that work because the limit for a clip is 10mb (if I remember correctly) and flutters framework is more than that. I could be wrong though. @xster

  3. jonahwilliams commented on Jun 22, 2020

    @jonahwilliams
    Contributor

    The default demo app is about 5.4 MB, that is plenty of room for small applications

  4. vincentracine commented on Jun 23, 2020

    @vincentracine

    As the adoption of NFC increases, this feature will become a must-have.

  5. newmskywalker commented on Jun 24, 2020

    @newmskywalker

    Would be great if it is cross platform. Clips for iOS, and Instant Apps for Android?

  6. marqueeeeeee commented on Jun 24, 2020

    @marqueeeeeee

    it looks like it is possible based from the initial documents and it is similar to universal links.

  7. xster commented on Jun 26, 2020

    @xster
    MemberAuthor

    right, the devil's in the details but from https://developer.apple.com/videos/play/wwdc2020/10174/, it seems so far like there aren't any blocking conceptual issues.

  8. added
    P3Issues that are less important to the Flutter project
    c: new featureNothing broken; request for a new capability
    on Jun 26, 2020
  9. chris-schra commented on Jun 29, 2020

    @chris-schra

    well, exporting thin builds of our full app most of them show around 10MB. Given that, I assume that a size-optimized target for App Clip including only necessary features should be well below 10 MB. I guess we'd just need a mechanism for the new target, right?
    Associated Domains feature is already integrated (for us, by using unilink package)

  10. anandat commented on Jun 29, 2020

    @anandat

    hmm right as per the app clip example given by apple ex : fruta

  11. Isakdl commented on Jun 30, 2020

    @Isakdl

    Really cool feature, would love to implement this in our app! These issues would probably help make this easier / viable #16815 #16813

  12. jmagman commented on Jun 30, 2020

    @jmagman
    Member

    I was able to create an App Clip running the Flutter demo by opening ios/Runner.xcworkspace in Xcode 12 and manually adding the target. This is not for the faint of heart and requires some Xcode knowledge to pull off.

    1. Open ios/Runner.xcworkspace
    2. Open the Project settings and hit the + to add a new target
      Screen Shot 2020-06-30 at 3 07 25 PM
    3. Add an App Clip Target
      Screen Shot 2020-06-30 at 3 08 52 PM
    4. Interface: Storyboard, Life Cycle: UI App Delegate
      Screen Shot 2020-06-30 at 3 09 05 PM
    5. When prompted, hit Activate.
      Screen Shot 2020-06-30 at 3 10 12 PM
    6. Delete the newly created AppDelegate.swift, ViewController.swift, Main.storyboard, Assets.xcassets, LaunchScreen.storyboard
      Screen Shot 2020-06-30 at 3 10 43 PM
      Screen Shot 2020-06-30 at 3 10 59 PM
    7. Open Project (not Target!) settings > Info > Deployment Configurations. Base the new App Clip target on the same configurations as your Flutter Runner target. This will give them access to all the Flutter build settings (build number from your pubspec.yaml, etc). So "None" will become either "Debug" or "Release". Set the iOS Deployment Target to 13 (I couldn't get this working on < 13).
      Screen Shot 2020-06-30 at 3 11 31 PM
    8. Open the App Clip entitlements file. Add the App Clip Associated Domains.
      Screen Shot 2020-06-30 at 3 12 54 PM
    9. Compile/embed your exiting Runner Swift files and assets into both Runner and the new App Clip target by setting the membership of each of the following files:
      AppDelegate.swift, ViewController.swift, Main.storyboard, Assets.xcassets, LaunchScreen.storyboard
      Screen Shot 2020-06-30 at 3 13 14 PM
      Screen Shot 2020-06-30 at 3 13 10 PM
      Screen Shot 2020-06-30 at 3 13 07 PM
      etc
    10. Open the App Clip Info.plist. Set Build version string (short) to $(FLUTTER_BUILD_NAME) and Bundle version to $(FLUTTER_BUILD_NUMBER). These need to match between the app and app clip target.
      Screen Shot 2020-06-30 at 3 13 43 PM
    11. Create a new entitlements file for your Runner app. Selecting the Runner group, File > New > File... Property List
      Screen Shot 2020-06-30 at 3 14 05 PM
    12. Call it Runner.entitlements (the entitlements extension is important) and add it to the Runner target.
      Screen Shot 2020-06-30 at 3 14 14 PM
    13. Add the same Associated Domains you added to the App Clip entitlements file. DO NOT add the Parent Application Identifiers.
      Screen Shot 2020-06-30 at 3 14 37 PM
    14. Open up your Runner target build settings. Set Code Signing Entitlements to the path of the Runner.entitlements file you just made, like Runner/Runner.entitlements.
      Screen Shot 2020-06-30 at 3 15 15 PM
    15. Open up your App Clip target build settings. Set iOS Deployment Target to iOS 13.0 (or just delete the setting to inherit).
      Screen Shot 2020-06-30 at 3 16 01 PM
    16. Still in your App Clip target build settings, in Framework Search Paths add $(inherited) and $(PROJECT_DIR)/Flutter in order so it can find the Flutter framework.
      Screen Shot 2020-06-30 at 3 16 31 PM
    17. Still in your App Clip target build settings, set Objective-C Bridging Header to Runner/Runner-Bridging-Header.h.
      Screen Shot 2020-06-30 at 4 23 17 PM
    18. Now go to your App Clip target Build Phases tab. Add a New Run Script Phase.
      Screen Shot 2020-06-30 at 3 18 00 PM
    19. Drag it it so it's right below Dependencies, and paste the following (this matches the build phase in your Runner target).
    /bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build

    This will compile your Dart code. This should only happen once when you build your project since the back end will cache the results.
    Screen Shot 2020-06-30 at 3 18 26 PM

    1. Make another New Run Script Phase. Drag it so it's below Copy Bundle Resources
    /bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed_and_thin

    This will embed your Dart code and the Flutter engine into the App Clip bundle.
    Screen Shot 2020-06-30 at 3 18 46 PM

    1. Run the App Clip scheme, targeting a iOS 14 device.
      scheme

    And it worked! Note the "Powered by" banner at the top.
    Screen Shot 2020-06-30 at 3 21 59 PM

    Caveats

    1. I make no guarantee of this working for your project, it's just a proof of concept to get you started. Please don't @ me to fix any linker errors, build setting problems, etc. 🙂
    2. Obviously this is all manual, and ideally Flutter tooling would do all this for you.
    3. I wasn't able to connect to the observatory, possibly because an entitlement is missing?
    4. This will embed your entire app into the App Clip. You'll need to figure out the right entrypoint (and create a separate AppDelegate for each target, don't share them). It needs to stay under 10MB per Apple's requirements.
    5. This could potentially be solved by embedding two Flutter add-to-app modules into a host app clip target?
    6. I didn't have any plugins. Hopefully it would be pretty easy to add the new target to your ios/Podfile but I didn't try, maybe (in master) something like:
    project 'RunnerAppClip', {
      'Debug' => :debug,
      'Profile' => :release,
      'Release' => :release,
    }
    ...
    target 'Runner' do
      flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
      target 'RunnerAppClip' do
        inherit! :search_paths
      end
    end

    Here's a zipped up version of that ios directory so you can open the Xcode project yourself and drop into a newly created flutter create test_appclip demo project. You'll need to change the signing team.
    ios.zip

  13. edeuss commented on Jun 30, 2020

    @edeuss

    @jmagman Wow, thanks for workaround. Also I think you meant 10mb not 10GB.

  14. 17 remaining items

  15. xster commented on Sep 26, 2020

    @xster
    MemberAuthor

    @miguelpruivo could you open a new issue for it? Sounds like you're asking for something slightly different than the premise of this bug. i.e. you want to have your App Clip be a standard SwiftUI App Clip rather than a Flutter powered App Clip while your main app is Flutter. Is that right? Could you describe your reproduction steps / project and the exact error?

  16. xster commented on Sep 26, 2020

    @xster
    MemberAuthor

    FWIW, this is what it's supposed to look like after you install the App Clip on your test phone and then scan a generated QR code following https://developer.apple.com/documentation/app_clips/testing_your_app_clip_s_launch_experience

    Screen Shot 2020-09-26 at 12 02 00 AM
    Screen Shot 2020-09-26 at 12 02 05 AM

    Another note: I never got the QR code scanning described in https://developer.apple.com/documentation/app_clips/testing_your_app_clip_s_launch_experience to work through the normal camera app for some reason. Though the built-in QR scanner that can be added to the Control Panel worked well.

  17. majingAragon commented on Sep 27, 2020

    @majingAragon

    I have added app clip into our flutter project and run well, but how to split part of plugins and assets out to app clip target? because app clip size has constraints.

  18. miguelpruivo commented on Sep 27, 2020

    @miguelpruivo

    @majingAragon I need to know this as well. Currently clip is inheriting all the Runner dependencies, which makes it bloated and bigger than 10MB.

  19. xster commented on Sep 28, 2020

    @xster
    MemberAuthor

    @majingAragon can you open another issue describing your issue? Splitting plugins and assets are likely not very useful unless you also split the Dart code referencing those different subsets of plugins and assets (which is currently not supported).

    We're doing some work in that area in #57617 and you can track our progress there.

  20. espling commented on Nov 5, 2020

    @espling

    When are you going to fully support app clips in a Flutter project? The official docs says that it's possible. I have succeded to create an app clip. But the size of a simple app clip, is way over the 10MB limit from just showing a simple screen. I've also tried to embed a simple swift view, without any shared resources from the main Flutter app. But the Flutter Framework is by default embedded in the app clip target. Therefore i wouldn't say that Flutter supports app clips yet.
    I've really tried everything to keep app clip size down to minimum but it's seems impossible. Am i doing something wrong or are you working to solve this issue?

  21. jmagman commented on Nov 5, 2020

    @jmagman
    Member

    I've also tried to embed a simple swift view, without any shared resources from the main Flutter app. But the Flutter Framework is by default embedded in the app clip target.

    If you don't have any Flutter elements in your app clip then you shouldn't be embedding any Flutter frameworks or plugins. There's no "default" here--you have control of what gets embedded in your app clip target.

    But the size of a simple app clip, is way over the 10MB limit from just showing a simple screen.

    Out of curiosity, how are you measuring it?

  22. espling commented on Nov 5, 2020

    @espling

    I've also tried to embed a simple swift view, without any shared resources from the main Flutter app. But the Flutter Framework is by default embedded in the app clip target.

    If you don't have any Flutter elements in your app clip then you shouldn't be embedding any Flutter frameworks or plugins. There's no "default" here--you have control of what gets embedded in your app clip target.

    But the size of a simple app clip, is way over the 10MB limit from just showing a simple screen.

    Out of curiosity, how are you measuring it?

    Ok, maybe i'm missing something then. I'll try to create the app clip again from scratch and see if i'm able to exclude the Flutter framework in some way. I'm not embedding it all, when archiving the app clip, the framework gets embedded.

    I measure my app clip as seen in apple documentation/guidelines. Archive and export as ad hoc or development, app thining and after that checking the app thinning size report text file.

    If anyone has done this successful (and keeping app clip size below 10MB) please let me know.

  23. jerryzhoujw commented on Nov 13, 2020

    @jerryzhoujw
    Contributor

    Update: it's not related to BitCode.

    With bitcode = YES, I can't distribute app with AppClip to apple store.

    Maybe it's apple's bug, not sure, I'm still searhing.

    distribute_with_bitcode_NO not work(Left) || distribute_with_bitcode_YES works(Right)
    distribute_with_bitcode_NOdistribute_with_bitcode_YES2

  24. espling commented on Dec 4, 2020

    @espling

    It's now official that it's not possible to ship an app clip in a Flutter app. The documentation is also updated with this information.

    #71098

    And this is a minimal app. My app is way bigger than this (and so is the app clip). Hope they will fix this asap.

  25. jmagman commented on Dec 4, 2020

    @jmagman
    Member

    Also note you can ship an app clip in a Flutter app, just not a FLUTTER app clip.

  26. espling commented on Dec 4, 2020

    @espling

    Also note you can ship an app clip in a Flutter app, just not a FLUTTER app clip.

    That's interesting. I've tried a native app clip embedded in a Flutter app. No luck, the app clip gets too big. But maybe i'm doing something wrong with the configuration for the app clip target. I would appreciate a small tutorial for that, because i've struggle hours.

  27. jmagman commented on Dec 4, 2020

    @jmagman
    Member

    You should just be able to open ios/Runner.xcworkspace, add the app clip target, and make sure not to reference Flutter at all. Flutter's pretty much just a few embedded frameworks in a normal iOS app, with a script to generate your compiled dart code, it's not that magic. So any vanilla non-Flutter App Clip tutorial online should work. You can dig into the generated App Clip bundle to make sure there's no Flutter pieces sneaking in.

  28. github-actions commented on Aug 9, 2021

    @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.

  29. locked as resolved and limited conversation to collaborators on Aug 9, 2021
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 projectc: new featureNothing broken; request for a new capabilitycustomer: crowdAffects or could affect many people, though not necessarily a specific customer.e: OS-version specificAffects only some versions of the relevant operating systemplatform-iosiOS applications specifically

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions