Workflow for creating a flutter app to deploy for desktop embedding on Windows

532 views
Skip to first unread message

clarke...@gmail.com

unread,
Jul 3, 2018, 1:29:34 PM7/3/18
to Desktop Embedding for Flutter
I've got an experimental windows desktop embedder going on top of a fork of Angle using a local build of the flutter engine for debugging purposes.  Now attempting to use it to run an actual Flutter project.  Not surprisingly, taking a hello world flutter project built with android studio using the installed version of flutter causes an invalid kernel binary format version assert in the bowls of Dart in my FlutterEngineRun() method.  Hence I'm trying to figure out the correct way to build a flutter package appropriately to consume in the embedder using my locally built flutter engine.  Specifically, I'm trying this from the flutter console:

C:\Users\james\source\temp>flutter create app

C:\Users\james\source\temp>cd app

C:\Users\james\source\temp\app>flutter build aot --local-engine=host_debug_unopt --local-engine-src-path /users/james/source/github.com/flutter/engine/src


But it no workie.  Clearly I'm doing something wrong / stupid.  Any pointers gratefully received.  Output from build:


Building AOT snapshot in release mode (host_debug_unopt)...
compiler message: U
compiler message: nhandled exception:
FileSystemException: Cannot open fil
compiler message: e, path = '\users\james\source\github.com\flutter\engine\src\out\host_debug_unopt\dart_entry_points\entry_points.json' (OS Error: The system cannot find the path specified.
, errno = 3)
#0      _File.throwIfError (dart:io/file_impl.dart:647)
#1      _File.openSync (dart:io/file_impl.dart:491)
#2      _File.readAsBytesSync (dart:io/file_impl.dart:551)
#3      _File.readAsStringSync (dart:io/file_impl.dart:596)
#4      NativeCodeOracle.processEntryPointsJSONFiles (package:vm/transformations/type_flow/native_code.dart:280)
#5      new TypeFlowAnalysis (package:vm/transformations/type_flow/analysis.dart:1163)
#6      transformComponent (package:vm/transformations/type_flow/transformer.dart:54)
#7      _runGlobalTransformations (package:vm/kernel_front_end.dart:128)
<asynchronous suspension>
#8      compileToKernel (package:vm/kernel_front_end.dart:71)
<asynchronous suspension>
#9      FrontendCompiler.compile.<anonymous closure> (package:vm/frontend_server.dart:329)
#10     new Future.<anonymous clo
compiler message: sure> (dart:async/future.dart:174)
#11     _rootRun (dart:async/zone.dart:1122)
#12     _CustomZone.run (dart:async/zone.dart:1023)
#13     _CustomZone.runGuarded (dart:async/zone.dart:925)
#14     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965)
#15     _rootRun (dart:async/zone.dart:1126)
#16     _CustomZone.run (dart:async/zone.dart:1023)
#17     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:949)
#18     Timer._createTimer.<anonymous closure> (dart:async-patch/dart:async/timer_patch.dart:21)
#19     _Timer._runTimers (dart:isolate-patch/dart:isolate/timer_impl.dart:382)
#20     _Timer._handleMessage (dart:isolate-patch/dart:isolate/timer_impl.dart:416)
#21     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:165)

Compiler terminated unexpectedly.





Chinmay Garde

unread,
Jul 3, 2018, 1:39:53 PM7/3/18
to clarke...@gmail.com, Desktop Embedding for Flutter
Great progress! Some pointers:
  • The embedder API currently is only configured for JIT mode execution of kernel snapshots.
  • Kernel binary version mismatches are probably because you used the Flutter release tooling with your own custom engine (which has a VM that is likely newer than the one released). Try `flutter --local-engine host_debug_unopt build bundle` to build the bundle with a kernel snapshot of the right version. Make sure to clear the build directory just in case because the tooling is sometimes confused when local engine development artifacts stick around.
If you are still getting version mismatches, can you please paste the output of the `build bundle` command with the -v flag turned on?

Chinmay

--
You received this message because you are subscribed to the Google Groups "Desktop Embedding for Flutter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-desktop-embe...@googlegroups.com.
To post to this group, send email to flutter-deskto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-desktop-embedding-dev/f8d3684a-c5f1-4ede-ae23-92a75757e1b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stuart Morgan

unread,
Jul 3, 2018, 1:56:38 PM7/3/18
to Chinmay Garde, clarke...@gmail.com, Desktop Embedding for Flutter
Just to add to what Chinmay said:
- 'flutter build bundle' is what we use on the other desktop platforms as well, so that's definitely what you should be using.
- I've mentioned before that the engine version must match the Flutter version, but I realized that the instructions for that aren't in this project any more now that both macOS and Linux use the prebuilt binaries fetched automatically via script. To do it manually, see the old Linux instructions for getting the right engine version.

Is the work so far all landed in your fork? I'd be very interested in seeing the current state!

-Stuart

Stuart Morgan

unread,
Jul 3, 2018, 2:02:22 PM7/3/18
to Chinmay Garde, clarke...@gmail.com, Desktop Embedding for Flutter
I should also mention that so far I've been focusing on tracking Flutter ToT, rather than using a release version (although eventually that will change, and I expect that this project will have versioning that tracks Flutter releases). A release version of Flutter may or may not be compatible, depending on how recent it is.

-Stuart

clarke...@gmail.com

unread,
Jul 4, 2018, 12:37:40 AM7/4/18
to Desktop Embedding for Flutter
Thx to both. That unblocked me. I was a bit thrown off by trying bundle on a more basic project which didn’t seem to be yielding expected results, i tried it with the test one in the desktop embedding repo and it worked great. My latest changes (in Angle, Engine, Embedder) are not all commited yet as I’m still peeling the onion with Angle.. Getting close to seeing pixels hopefully jump tables not withstanding, when I do get something E2E will get it in. Will be away for a few days from tomorrow doing RNR, hoping to make progress over the weekend. Thx Again, James

clarke...@gmail.com

unread,
Jul 8, 2018, 11:13:09 AM7/8/18
to Desktop Embedding for Flutter
On Tuesday, July 3, 2018 at 9:37:40 PM UTC-7, clarke...@gmail.com wrote:
> Thx to both. That unblocked me. I was a bit thrown off by trying bundle on a more basic project which didn’t seem to be yielding expected results, i tried it with the test one in the desktop embedding repo and it worked great. My latest changes (in Angle, Engine, Embedder) are not all commited yet as I’m still peeling the onion with Angle.. Getting close to seeing pixels hopefully jump tables not withstanding, when I do get something E2E will get it in. Will be away for a few days from tomorrow doing RNR, hoping to make progress over the weekend. Thx Again, James

I got the remainder of the Angle hookup done and have got a little further as I see a bunch of text rendered (by Skia, yea!) saying Unknown platform: windows was not recognized as a target platform. Consider updating the list of TargetPlatforms to include this platform.

Having done some searchs in the Engine codebase, I’m concluding that this message is being emitted by the Flutter Framework.. is there any way of surpressing it and having Flutter load the package I’m asking it to load or do I need to make a private build of the framework and or tools and actually go update the TargetPlatforms list?

Callum Iddon

unread,
Jul 8, 2018, 7:44:41 PM7/8/18
to Desktop Embedding for Flutter
You are correct in the Flutter framework throwing that error. I have gotten a basic rendering and pointer events embedder working using GLFW and have written instructions here on how to add Windows as a target platform.

clarke...@gmail.com

unread,
Jul 9, 2018, 2:06:54 AM7/9/18
to Desktop Embedding for Flutter
Thx.  Turns out the error was coming from the plugin from the test app which I have not yet implemented, I have hello world working just fine with my impl now.  There may be aspects of your impl I can leverage but since I'm going for a "pure" Windows approach using Win32 directly (and UWP API's once I have that version of the engine working), Angle for rendering,the Windows compositor, C++/WinRT etc, rather than GLFW I'll likely keep my fork separate for now.

clarke...@gmail.com

unread,
Jul 9, 2018, 2:06:16 PM7/9/18
to Desktop Embedding for Flutter


PlatformNotSupported is still biting me even for a project without plugins.

This is helloworld from flutter examples


This is flutter create newApp:


both built against my local engine with flutter build bundle --local-engine=host_debug_unopt --local-engine-src-path /users/james/source/github.com/clarkezone/flutter/engine/src

@callum Iddon I think you posted instructions for adding windows as a supported platform but can't see the post in the thread

Chinmay Garde

unread,
Jul 9, 2018, 2:33:13 PM7/9/18
to James Clarke, Desktop Embedding for Flutter
The PlatformNotSupported limitation is probably the framework being confused about seeing a platform it hasn't seen before. Patching the TargetPlatform enum or the defaultTargetPlatform getter to mimic one of the supported platforms when on Windows should do the trick. If you have a patch that does this already, can you send a PR?

Chinmay

--
You received this message because you are subscribed to the Google Groups "Desktop Embedding for Flutter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-desktop-embe...@googlegroups.com.
To post to this group, send email to flutter-deskto...@googlegroups.com.

Stuart Morgan

unread,
Jul 9, 2018, 2:56:37 PM7/9/18
to Chinmay Garde, James Clarke, Desktop Embedding for Flutter
For a random Material Flutter app the exception is expected since MaterialApp calls defaultTargetPlatform if one isn't provided. That shouldn't happen with current versions of the f-d-e example app though since it now sets a target platform explicitly, so I'm curious to build the Windows GLFW PR and see where the exception is coming from in that case.

Regardless of the specific source, I'll send a PR shortly to add Windows to the list of hosts that are treated as Android. That seems like the simplest solution for now, since defaulting to an existing target platform is how macOS and Linux are currently handled. Longer term, hopefully desktop platforms can become target platforms, but that has larger implications.

-Stuart


Stuart Morgan

unread,
Jul 9, 2018, 4:08:05 PM7/9/18
to Chinmay Garde, James Clarke, Desktop Embedding for Flutter
On Mon, Jul 9, 2018 at 11:56 AM Stuart Morgan <stuart...@google.com> wrote:
That shouldn't happen with current versions of the f-d-e example app though since it now sets a target platform explicitly, so I'm curious to build the Windows GLFW PR and see where the exception is coming from in that case.

It turns out the explicit target platform is not actually used by everything (at least some of which are probably bugs), which is why the example app still explodes.

I've sent https://github.com/flutter/flutter/pull/19176 to add a Windows->Android mapping, which hopefully won't be controversial.

-Stuart

James Clarke

unread,
Jul 9, 2018, 4:17:37 PM7/9/18
to Stuart Morgan, Chinmay Garde, Desktop Embedding for Flutter
Awesome!  If I make that corresponding change in my local copy of the file, presumably I need to rebuild the foundation package before recompiling the app itself?  If yes how do I do that? (Sorry for nube question) 

Stuart Morgan

unread,
Jul 9, 2018, 4:30:58 PM7/9/18
to James Clarke, Chinmay Garde, Desktop Embedding for Flutter
Just re-running 'flutter build bundle' should be all you need; that's the step that snapshots everything into a kernel file.

-Stuart

clarke...@gmail.com

unread,
Jul 9, 2018, 5:09:58 PM7/9/18
to Desktop Embedding for Flutter
Awesome in business now!


Will get mouse hooked up, do some cleanup and get this into my fork!

Chinmay Garde

unread,
Jul 9, 2018, 5:11:22 PM7/9/18
to James Clarke, Desktop Embedding for Flutter
Thats impressive. Looking forward to it.

--
You received this message because you are subscribed to the Google Groups "Desktop Embedding for Flutter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-desktop-embe...@googlegroups.com.
To post to this group, send email to flutter-deskto...@googlegroups.com.

Stuart Morgan

unread,
Jul 9, 2018, 6:36:30 PM7/9/18
to Chinmay Garde, James Clarke, Desktop Embedding for Flutter
On Mon, Jul 9, 2018 at 1:07 PM Stuart Morgan <stuart...@google.com> wrote:
I've sent https://github.com/flutter/flutter/pull/19176 to add a Windows->Android mapping, which hopefully won't be controversial.

This ended up being somewhat controversial :) Expect some churn around this in the near future on the Flutter side; I'll update the example app, and this mailing list, once the replacement approach is in place.

-Stuart
Reply all
Reply to author
Forward
0 new messages