flutter for apple tv
a modification of the flutter engine + test application to demonstrate that flutter applications run on apple tv
this project (and liberty global repositories referred to) are for testing purposes only!
flutter and the related logo are trademarks of google llc we are not endorsed by or affiliated with google llc.
approach:
- engine:
- use
ios
target to compiletvos
target- it is possible to create a new
tvos
target, but this would have impact and more files would need to be changed and therefore require more effort to maintain apple tv support in the engine- this can be done by modifiying the makefiles in the different projects
- see ‘real_tvos_target’ branch (not finished!)
- instead of using
ios
sdk,tvos
sdk is used
- it is possible to create a new
- disable/replace code not supported by
tvos
sdk - added support for apple tv remote
- swipe
- based on gesture recognizer & game controller
- created new channel to forward movement to application
- application translates movement to left, right, up & down
- handling this in the application allows the application to optimize the speed etc per screen / use-case
- remote keys:
- menu, play-pause, … are mapped to key codes
- menu key is mapped to “poproute” function, but could be mapped to ‘back’ key
- keyboard input:
- 1.26: support for ios keyboard and no modifications needed.
- in flutter 1.15/1.19/1.22 a subset of keys is mapped to “macos” and “android” key codes
- swipe
- enabled bitcode (mandatory for apple tv)
- repositories modified
- https://github.com/flutter/buildroot –> https://github.com/libertyglobal/flutter-tvos-buildroot
- https://github.com/flutter/engine –> https://github.com/libertyglobal/flutter-tvos-engine
- https://dart.googlesource.com/sdk –> https://github.com/libertyglobal/flutter-tvos-dart
- https://skia.googlesource.com/skia –> https://github.com/libertyglobal/flutter-tvos-skia
- tested flutter engines:
- 1.15, 1.19-candidate-4, 1.22-candidate.13, 1.26.0-17.6-pre, 2.0.4
- use
- framework
- no modifications in “flutter” tool (/framework)
- platform
tvos
not supported,ios
target cannot be used because without modifications it would the use wrong sdk(ios) to compile the application
- application
- changes compared to
ios
application setup:- modified main storyboard
- icon set for tvos
- custom script to compile application which replaces
code_backend.sh
in the “build phases” step. this script is based on scripts from the engine test application which only use tools from the engine. the normal script cannot be used because it used the standard “flutter” tool which does not supporttvos
.
- copy generated resources from real
ios
app target. the test app target actually overwrites theios
build to use the resources. - change targets for application and pods to ‘tvos’ and set minimum os version to 12.0
- changes compared to
known limitations
- not all pods will compile.
ios
target is used and some api’s are not supported bytvos
. e.g. webview - no debugging capabilities
- no apple tv look and feel widgets, no integration of virtual keyboard, …
- resource monitoring is not supported by tvos (using flutter tools)
known issues
- when a debug version is installed on a simulator or apple tv device, then the app will not load when selected on screen. it will only load from the xcode debugger. this is not an issue for release builds. this has most likely to do with the fact that the app is trying to connect to 127.0.0.1 which is not started because the flutter tools are not used.
supported devices
- apple tvos 12.0 or later
workarounds
- disabled download commands etc. in
process_macos.cc
- this should not be needed and only be compiled for host
- https://github.com/dart-lang/sdk/issues/39918#issuecomment-569806159
- disabled fatal error in
kernel_translation_helper.cc
, still to be investigated what the root cause is
setting up engine / development environment
- host compilation (macos) fails on system with 16gb memory, no issues on 32gb mac
- added
--no-lto
flag, see https://github.com/flutter/flutter/issues/57207
- added
- based on instructions here: https://github.com/flutter/flutter/wiki/setting-up-the-engine-development-environment)
- create empty directory called
engine
for you local copy of the repository andcd
into it. (some tools assume this folder name!) - create a
.gclient
file in engine directory with the following contents:{ "managed": false, "name": "src/flutter", "url": "https://github.com/libertyglobal/[email protected]", "custom_deps": {}, "deps_file": "deps", "safesync_url": "", }
- run
gclient sync
inengine
directory - see flutter wiki for java skd and ‘ant’ dependencies
- install “flutter” version
2.0.4
(https://flutter.dev/docs/get-started/install/macos)
compiling the engine
- the script will build 5 targets for tvos in the src/out folder:
- ios_debug_unopt, ios_debug_sim_unopt, ios_release, host_debug_unopt and host_release release
- note: fectching all repositories and compiling the engine for apple tv (all targets) requires at leaste
29gb
of free diskspace! - run in
/engine/src/
scriptsh ninja_build.sh
(located in script folder, see )- add paramter
clean
for a full rebuild. - note: the
--no-lto
flag can be removed on 32gb host systems
- add paramter
- based on: https://github.com/flutter/flutter/wiki/compiling-the-engine. the problem with the order described on this wiki is that the generated files for the host point to the ios/tvos sdk instead of macos
compiling application
- 1st build real ios target to make sure the resources(images, fonts, …) are generated by the flutter tools and can be used for tvos
flutter build ios
- note: the application will regardless of the target, always be compiled to
/build/ios/release-iphoneos
. the main reasone for this is that the resouces generated by the normal ios build are located here and are re-used.- this means that if any of the resource will change, added or removed that normal ios build must be done first. in order to do this, the step below must be un done first!
- rename tvos folder to ios
- flutter tools assume the folder name is
ios
. flutter pub get will fail if the folder has a different name! - run command:
sh scripts/switch_target.sh tvos
- (to switch back to ios:
sh scripts/switch_target.sh ios
)
- flutter tools assume the folder name is
- run command:
flutter pub get
- go to
ios
folder - install/get cocoa pods
- run command:
pod install
- pods target is automatically corrected from ios to tvos in
podfile
post_install step
- run command:
- copy flutter framework to pods
- run command:
sh ../scripts/copy_framework.sh debug_sim <path to local flutter engine>/engine/src
- copies debug simulator version. the correct version (debug, sim, release/archive) will be copied during app compilation
- unfortunately this is a manual step, because the pods are compiled first as a dependency by xcode and there is no hook in the xcode build process before this to automatically copy the right frame work to be used based on the selected target
- run command:
- open in ios folder
runner.xcworkspace
- set path to local compiled flutter engine in
flutter_local_engine
(src folder) - e.g.
flutter_local_engine = <your local path to flutter engine>/engine/src
- alternatively run:
sed -i '' "s#flutter_local_engine[[:space:]]=[[:space:]].*;#flutter_local_engine = "${flutter_local_engine}";#g" runner.xcodeproj/project.pbxproj
- set path to local compiled flutter engine in
- build app for device debug, simulator or archive (see switching target below)
Comments are closed.