VistianOpenSource / Vistian.Flutter.Bindings

An experimental release allowing Flutter solutions to be hosted within Xamarin solutions
31 stars 4 forks source link

Support Flutter 1.0 Android and iOS #2

Open VincentH-Net opened 5 years ago

VincentH-Net commented 5 years ago

Great project! This looks like the currently feasible way to use Flutter and Xamarin ios / android in a production app. I already heard other people did their own binding, much better to share.

Would be great to have Flutter 1,0 bindings for Android and iOS

VistianOpenSource commented 5 years ago

I will look to get around to doing it, probably over the next week or so. I was a little surprised given the 4000+ issues lodged against flutter that they pushed out a release but...

VincentH-Net commented 5 years ago

Great! I'll do a POC once you have the 1.0 support. Evaluating whether I can move my Xamarin Forms production app to this :-)

VincentH-Net commented 5 years ago

It seems like the flutter_assets (material + cupertino icon fonts, kernel bin 14 mb, snapshot data 3 mb) are missing in FlutterHost. Is referencing flutter-debug.aar and icodtl.dat enough? (see flutters-compilation-patterns for background of kernel and snapshot)

Here is what I found:

1) I succesfully created an Android app that contains a Flutter module in Android Studio on Mac, as described in Add-Flutter-to-existing-apps (based on the Flutter Master channel since Add2App is still in preview). This gave me a working Android app with Flutter embedded.

2) I updated the FlutterHost Android app with the flutter-debug.aar and icudtl.dat from step 1 above; I could build and start it, but on creating the flutterview it crashed.

When I compare the APK's from step 1 and 2, the Flutter assets are missing in the FlutterHost APK. It seems to me this approach cannot work without these assets?

The cause of this seems to be that the binding project only includes the flutter-debug.aar, which can be created directly from the Flutter project without embedding the Flutter project in an Android app, as mentioned in Add-Flutter-to-existing-apps.

However, when I create this .aar it does not contain the Flutter assets, only libflutter.so, a small flutter.jar and some generated java classes (the C# equivalents of which are in the Flutter.Bindings.Extensions project).

How to get this working?

VistianOpenSource commented 5 years ago

Hi, I've been out or day, so not had time to check things yet, but a few things come to mind:

  1. You are running the same version of Flutter that this was done for (when using what you can get from your flutter install)?
  2. Yes, just referencing the Vistian.Flutter.Bindings should be sufficient - it contains the aar file.
  3. The FlutterView could crash if the icodtl.dat file isn't there / not in the correct place.
VincentH-Net commented 5 years ago

Hi, thx for responding quickly. I just thought I could try updating this to 1.0 for Android

1) No, this is for Flutter 1.0 from Master channel. So I had to update the files in my step 2 above.

2) So the material + cupertino icon fonts are somewhere in the .aar? Or are they not needed? Or we should add them manually in the host? I can imagine that the kernel bin and snapshot data may not be needed if those are just alternate compilations of code that is already in libflutter.so - is that the case?

3) Yes I read that and checked

I tried to get ahead at least in version 1.0 for android, but maybe it is best if I wait for you to update it :-) Thx AOT

VistianOpenSource commented 5 years ago

AFAIK all of the things required for a 0.9.4 installation were contained within the aar file. I should caveat this that I did do this work also for a 0.8.x release of flutter and there were changes between what I had to do then and the instructions for 0.9.4 so it could be that things have changed again between 0.9.4. and 1.0. I do remember doing a clean solution and using the package to check that it worked, and it did at the time, but if you can hang on I can have a look on Monday/Tuesday and look to get a cut done for 1.0. If 1.0 is a 'stableish' release I'll also do the iOS version-it is a bit of a pain to do given you have to adjust the objective-c mappings manually to get it to work.

VincentH-Net commented 5 years ago

That would be great, I'll try to contain my curiosity for a few more days.

I have worked out an approach to migrate a Xamarin Forms app to Xamarin Classic + Flutter, keeping existing ContentPages with forms native views, mixing with Flutter. Only need to rewrite my Forms navigation service to 2 classic ones. Bindings are the only missing piece, eager to poc this.

VistianOpenSource commented 5 years ago

There is now a beta release version for 1.0 Android up on nuget. Just choose the pre-release option to see it.