How to export Flutter project as SDK (iOS dynamic framework)
I've partially achieved what you want. All of this is very experimental and overall a bad idea for production ready SDK. But... it's possible.
- Create flutter app as usual and run it once on iOS simulator.
- Open Xcode workspace and add new framework. For my purposes I will name it RunnerLib.
- Change deployment target of that framework to be the same as for Runner. Also disable bitcode.
- Change target membership of App.framework and Flutter.framework to RunnerLib.
- Create Launcher class with one static method:
+ (void)launchFrom:(UIViewController *)parent
, this what should create a FlutterViewController and present it. - Rewrite the Runner to use Launcher class. Replace FlutterAppDelegate with standard AppDelegate, make ViewController, etc. It should look like standard native iOS project, so you could create one and copy over AppDelegate, storyboard and ViewController.
- Call launchFrom method in your view controller, in viewDidAppear or as IBAction on a button.
- You should be able to build the Runner and see that flutter screen appears.
- Now, if you build the Runner app, you can open the crated Runner.app, and see that Frameworks directory contains 3 frameworks: App, Flutter and Runner.
- You will need to have two sets of frameworks: one set for simulator, compiled in debug mode, and another set for devices - archived. Getting debug frameworks is pretty easy, just compile from Xcode and inspect the product. Archived frameworks are harder, I recommend doing
xcodebuild archive
with disabled signing. - Your users will have to configure their project to use correct frameworks depending on device. Possibly this step can be automated by Carthage and fat binaries, but I'm not sure. The problem is with App.framework which looks completely different on device than on simulator.
Source code: https://github.com/szotp/runner_lib
In order to export the framework as a native library you'll have to ensure that the person who'll use your framework (user) has Flutter SDK installed onto his computer as your framework's code will surely be dependent on Flutter SDK by default. So what your trying to do is equivalent of having your own package on pub.dev.
If you find some way to make the framework you want to export - independent of Flutter's framework, only then exporting it as an framework would make sense. (Doing that should be possible beyond doubt, but see the amount of work and time you'll put in just to get your framework there. You could have built your own Flutter framework in those same efforts and time)
Since you have already made that awesome Flutter Project, consider uploading it as an package on https://pub.dev/ if you wish to.
Suggestion: You can ask the users who want to try your package to install Flutter. This way your hardwork won't go in vains.
Conclusion: It is not practically feasible to achieve what your trying to do.