Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bitcode support for iOS #15288

Closed
eseidelGoogle opened this issue Mar 8, 2018 · 113 comments · Fixed by #39357 or #39434
Closed

Add Bitcode support for iOS #15288

eseidelGoogle opened this issue Mar 8, 2018 · 113 comments · Fixed by #39357 or #39434
Assignees
Labels
a: annoyance Repeatedly frustrating issues with non-experimental functionality c: new feature Nothing broken; request for a new capability engine flutter/engine repository. See also e: labels. platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Milestone

Comments

@eseidelGoogle
Copy link
Contributor

Apple may eventually require Bitcode support for iOS. It's currently required for submissions to tvOS and watchOS stores.

We've seen Dart's toolchain produce Bitcode as a demo:
https://medium.com/dartlang/dart-on-llvm-b82e83f99a70

This bug tracks (eventually) turning that demo into a production solution.

@eseidelGoogle eseidelGoogle added the platform-ios iOS applications specifically label Mar 8, 2018
@eseidelGoogle eseidelGoogle added this to the 6: Future Future milestone Mar 8, 2018
@ngocdaothanh
Copy link

Bitcode support is also being added to Kotlin-Native:
JetBrains/kotlin-native#1564

@ngocdaothanh
Copy link

Hi, is there any progress on this feature?

@dnfield
Copy link
Contributor

dnfield commented Oct 11, 2018

Additional reason:

  • In an Add2App scenario, anyone using Flutter in their app can no longer use bitcode, and all targets/projects in their workspace will have to disable it.

@wederchr
Copy link

wederchr commented Oct 15, 2018

Hi Team,

I understand that Bitcode support is not a high prio feature for most Flutter users. However, for security critical apps Bitcode support is crucial since most app hardening frameworks rely on it. Meaning apps that need to be hardened (e.g. for legal reasons) cannot be developed with Flutter. Would you kindly reconsider the prioritization of this feature?

@zoechi zoechi added the c: new feature Nothing broken; request for a new capability label Oct 15, 2018
@eseidelGoogle
Copy link
Contributor Author

@yapcwed I would like to learn more about that use case. Can you point us to some example hardening frameworks which depend on bitcode?

@evant
Copy link

evant commented Oct 24, 2018

@magnatronus
Copy link

magnatronus commented Oct 30, 2018

Hi,

so as far as I understand this is causing the issue I have put on StackOverflow here:
https://stackoverflow.com/questions/53048589/adding-a-watch-app-to-a-flutter-ios-application
Which means that no iOS Flutter based apps can have an associated WatchOS app added to them.

Is this correct?

@eseidelGoogle
Copy link
Contributor Author

@magnatronus looks unrelated to bitcode, but I don't know for sure. @xster or @dnfield might.

@xster xster added this to Large Features in iOS Framework Oct 30, 2018
@dnfield
Copy link
Contributor

dnfield commented Oct 31, 2018

tvOS and watchOS stores require bitcode.

@dnfield dnfield added the dependency: dart Dart team may need to help us label Oct 31, 2018
@yvnalor
Copy link

yvnalor commented Nov 5, 2018

Need this feture too,otherwise app's size may increasing

@fvisticot
Copy link

Need iWatch and tvOS as well !

@sgalway00
Copy link

Also looking for WatchOS support.

@Portalesoft
Copy link

+1

@zoechi zoechi added tool Affects the "flutter" command-line tool. See also t: labels. engine flutter/engine repository. See also e: labels. labels Dec 17, 2018
@gimox
Copy link

gimox commented Jan 4, 2019

Adding bitcode for iOs is mandatory for me . Without AppleTv or iWatchKit is not possibile to valuate Flutter as full replacement language for mobile. Please consider to increase task priority!

@zoechi
Copy link
Contributor

zoechi commented Jan 4, 2019

@gimox you have the power to increase priority by upvoting the initial comment.

@Portalesoft @fvisticot @sgalway00

Using "add reaction" on the initial comment would increase priority while +1 comments are rather pointless and cause lots of people to get notified for no reason.
To get notified yourself use the [Subscribe] button to the top right instead.

Also upvotes on follow-up comments don't increase priority.

@magnatronus
Copy link

magnatronus commented Jan 28, 2019

@eseidelGoogle my tests adding a watch app to an iOS app have moved on. I now kinda have it working.

My test Flutter project can be found here. As far as I have got it does basically works (I am yet to try and add a Watch Session to enabled real time comms). But I have come across an issue with Flutter (maybe?) which I have commented on in my project. The basic issue is that once I have added the Watch Kit target to the iOS project Flutter refused to either do a run or an iOS build. But if I use XCode directly I can get it to work, in both cases.

@dnfield
Copy link
Contributor

dnfield commented Jan 28, 2019

@magnatronus that sounds pretty interesting. Can you provide any more details about how you added it to the project and got it to build? The normal way of doing this should trigger the same error as you're seeing.

AFAIK (and I may very well be wrong), you need to have bitcode enabled to submit to the store for watch apps. Are you able to submit your working version to the store?

@magnatronus
Copy link

@dnfield Basically I created a standard Flutter app, then in the iOS project just add a new target of a Watch Kit app (details in my project readme). After doing this it will not build/run using the Flutter tooling, but directly in the iOS project it will.

I built out the Watch App in XCode using Swift.

At the moment I have only build AD-HOC, but the steps are basically

  • Set Device to Generic Device
  • Build Archive
  • In Organiser select project/Distribute App button
  • Select the AD- Hoc option

At this point it offers 3 options (2 auto selected - which I left), which were

  • Rebuild from BitCode
  • Strip Swift Symbols

I then manually signed the app and then waited while it built the distro. This takes a while as it looks like it is rebuilding with BitCode.

The resulting IPA file is usable for test distro (I used HockeyApp for this) and have both the iOS app and the installed Watch App on my devices.

I want to try adding Watch session first, if that works I will try a store submission.

@dnfield
Copy link
Contributor

dnfield commented Jan 28, 2019

Very cool - please do let us know if these steps end up working for the store!

@magnatronus
Copy link

magnatronus commented Jan 29, 2019

@dnfield I now have the Watch Kit session communicating with the Flutter app. Need to tidy up both code bases then I will try an app Store submission.

@vitor-gyant
Copy link

@dnfield Great. I'll give it a try.

@ngocdaothanh
Copy link

@dnfield Many thanks for the great work.

Can you give an instruction where to put ENABLE_BITCODE?

I guess it's ENABLE_BITCODE=yes flutter build ios (https://flutter.dev/docs/deployment/ios)?

@vitor-gyant
Copy link

vitor-gyant commented Sep 2, 2019

@dnfield I'm facing a strange error while testing this. So, I've created a new flutter project, enabled bitcode on the app target and tried to archive the app which went just fine. I've added local_auth package to pubspec, , removed the post_install hook on pod file that disables bitcode for all the plugin targets and tried to archive but now it fails.

ld: warning: Could not find auto-linked framework 'Flutter'
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_FlutterError", referenced from:
      objc-class-ref in LocalAuthPlugin.o
  "_OBJC_CLASS_$_FlutterMethodChannel", referenced from:
      objc-class-ref in LocalAuthPlugin.o
  "_FlutterMethodNotImplemented", referenced from:
      -[FLTLocalAuthPlugin handleMethodCall:result:] in LocalAuthPlugin.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there anything missing on my side ? thanks

@larryaasen
Copy link

@vitor-gyant When you added local_auth to your pubspec, did you point to the version on pub.dev, or did you point to the one in master? If you pointed to the one in pub.dev, maybe the iOS project that gets generated is not compatible. Try pointing directly to master.

@vitor-gyant
Copy link

@larryaasen Thanks but it does not work too. I don't think this has something to do with the plugin itself since bitcode support has no impact on the current source code.

@vitor-gyant
Copy link

I should say that compiling in release works just fine. Compiling for Generic iOS Device too. Archive is the only step where the error occurs.

@dnfield
Copy link
Contributor

dnfield commented Sep 2, 2019

I'll try this when I'm back at my desk tomorrow. It's likely there's still some work to do for plugins.

@dnfield
Copy link
Contributor

dnfield commented Sep 4, 2019

@vitor-gyant - I was able to export a bitcode enabled app, but I did have to make sure to manually set ENABLE_BITCODE to YES for the Pods target. I've filed #39793 to track making that work better by default.

@danallen88
Copy link

Even when enabling bitcode for the Pods target, I'm still unable to build or archive in XCode - even when using a Generic iOS Device as the target. The error I'm getting is:

ld: library not found for -lFirebaseCore clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've tried manually linking this library in the WatchKit extension targets to no effect. I imagine this points to dependencies needing bitcode support as well? Am I understanding that correctly? It seems odd that the WatchKit app would need to care about the iPhone dependencies at all. The only report I've seen of this working (from @magnatronus) is a trivial app with no dependencies.

@dnfield
Copy link
Contributor

dnfield commented Sep 4, 2019

Yes. All of your targets must have bitcode enabled, and any frameworks your linking in must have been built with bitcode. I know I've seen at least one plugin out there that isn't (connectivity).

@danwulff
Copy link

danwulff commented Sep 4, 2019

@dnfield I tried to do a quick glance through of some of the flutter/packages to determine whether the iOS side has bitcode enabled or not but I couldn't get a clear understanding of what that looks like.

Could you give an example of how a package is setup to support bitcode, and what file that support lives in.

@dnfield
Copy link
Contributor

dnfield commented Sep 4, 2019

It has to be built with ENABLE_BITCODE set to yes. There's no one good place to look for that - it could be in the .pbxproj for that project, or it could be in a .xcconfig that was used to build it. Unfortunately, the best way to tell is to try to build the library with bitcode and see if Xcode complains that some framework wasn't built with bitcode. If so, it will suggest you rebuild it with bitcode or request that the author ship a binary with bitcode.

Many flutter plugins should work - for example, local_auth definitely works. This should always be true if you're compiling the plugin from source yourself. However, you may run into trouble if you have a binary distribution that was not built with bitcode.

@danwulff
Copy link

danwulff commented Sep 4, 2019

@dnfield Thanks so much for the further details. That makes more sense.

I imagine we will see some issues created for packages that aren't compatible in the coming weeks.

@dnfield
Copy link
Contributor

dnfield commented Sep 4, 2019

I've updated https://github.com/flutter/flutter/wiki/Creating-an-iOS-Bitcode-enabled-app-(experimental) with some more instructions/details around this.

@danallen88
Copy link

Would you mind sharing what you have configured for your Library Search Paths when you have dependencies like url_launcher? My troubleshooting up to this point has led me to believe that the project default is incorrect and causing the ld: library not found for -l<lib_name> errors.

@dnfield
Copy link
Contributor

dnfield commented Sep 5, 2019

My library search paths are blank - I did this in just a brand new project:

flutter create bitcode_plugin_test
cd bitcode_plugin_test
# add plugin to pubspec.yaml
open ios/Runner.xcworkspace
# Select signing information, set ENABLE_BITCODE to Yes, Build

@danallen88
Copy link

Thank you for the support, @dnfield. I'll be curious to see if others are able to take an existing Flutter repo, make the updates to support bitcode, and add a WatchKit extension without issue. The documentation you've provided has been very helpful in understanding what needs to happen to enable bitcode, so I think at this point the issues I'm experiencing are project-related and not necessarily framework-related.

@filiph filiph added the a: annoyance Repeatedly frustrating issues with non-experimental functionality label Sep 11, 2019
@vitor-gyant
Copy link

@dnfield Did you have the opportunity to test a sample app with at least one plugin (url_launcher) exported with bitcode enabled ? I have tried in a new flutter project with just url_launcher in the pubspec and still get the following error only when archiving:

ld: warning: Could not find auto-linked framework 'Flutter'
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_FlutterMethodChannel", referenced from:
      objc-class-ref in UrlLauncherPlugin.o
  "_OBJC_CLASS_$_FlutterError", referenced from:
      objc-class-ref in UrlLauncherPlugin.o
  "_FlutterMethodNotImplemented", referenced from:
      -[FLTUrlLauncherPlugin handleMethodCall:result:] in UrlLauncherPlugin.o
ld: symbol(s) not found for architecture arm64

Since url_launcher is a source code dependency I don't see a problem related to it. I've change the podfile to set ENABLE_BITCODE to YES. Also double check that every bitcode setting is now YES in the both app and pods target.

Is this something you're working on ?

Thanks,

@dnfield
Copy link
Contributor

dnfield commented Sep 12, 2019

@vitor-gyant - I did successfully build and archive the Flutter Gallery with bitcode since this.

When you go to archive, are you sure you're archiving release mode? And are you sure you enabled bitcode on the pods targets as in the linked wiki page ( https://github.com/flutter/flutter/wiki/Creating-an-iOS-Bitcode-enabled-app-(experimental))?

@vitor-gyant
Copy link

@dnfield It seems my working copy was not in a good "shape". After running flutter build --ios it work as expected. What was strange was that changing the configuration to release in Xcode and compiling did not have the same effect of running flutter build --ios.

@zeucxb
Copy link

zeucxb commented Oct 26, 2019

Are there some example using bitcode to watch apps?

@peroksid90
Copy link

I have checked bitcode which gets generated for the test project
Runner.app/Frameworks/App.framework/
and it looks like that is not "real" bitcode, but a Mach-O binary file instead.

There should be files like 1, 2, 3, 4,... of LLVM bitcode type and wrapper. And you should be able to process those using llvm-dis. However, we get a Mach-O binary there.

I have used bitcode_retriever tool to extract xar files from Runner.app/Frameworks/App.framework/App:

shell $ bitcode_retriever App
arm.xar
arm64.xar

shell $ xar -xf arm64.xar
shell $ file 1
1: Mach-O 64-bit object arm64

If you did the same for Runner.app/Runner binary, you would get correct bitcode of LLVM bitcode type:

shell $ bitcode_retriever Runner
arm.xar
arm64.xar

shell $ xar -xf arm64.xar
shell $ file 1
file 1
1: LLVM bitcode, wrapper

The root cause of that issue is that an assembly file got put as input for clang:

Clang produces correct xars that carry LLVM bitcode if you pass unmanaged code or llvm-bitcode, and set -fembed-bitcode flag (it is possible to re-create a binary containing bitcode from bitcode).

If it was possible to get Dart compiled into llvm-bitcode, it would be proper bitcode-enabled archives generated.

Thus, even it is now possible to build projects with BITCODE_ENABLE=YES, the community I believe is still facing the following issues:

  1. Compatibility with analysis tools such as Veracode
  2. Use of app-hardening solutions (rely on bitcode)

@dnfield
Copy link
Contributor

dnfield commented Dec 10, 2019

@peroksid90 - it would probably be helpful to discuss this in a new issue. Feel free to tag me in it.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2021
@jmagman
Copy link
Member

jmagman commented Jul 19, 2022

This issue is very old, but for interested parties: due to Apple dropping bitcode in an upcoming release, Flutter will be removing support for bitcode.

Starting with Xcode 14, bitcode is no longer required for watchOS and tvOS applications, and the App Store no longer accepts bitcode submissions from Xcode 14.

Xcode no longer builds bitcode by default and generates a warning message if a project explicitly enables bitcode: “Building with bitcode is deprecated. Please update your project and/or target settings to disable bitcode.” The capability to build with bitcode will be removed in a future Xcode release. IPAs that contain bitcode will have the bitcode stripped before being submitted to the App Store. Debug symbols for past bitcode submissions remain available for download. (86118779)

https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes

Work tracked in #107887. Please file new issues if you see bugs or have documentation requests. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: annoyance Repeatedly frustrating issues with non-experimental functionality c: new feature Nothing broken; request for a new capability engine flutter/engine repository. See also e: labels. platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet