Problem with "add to app": Could not launch engine with configuration

1k views Asked by At

I'm struggling to integrate a Flutter Module into a Swift application. I have followed Flutter documentation (Integrate a Flutter module into your iOS project), and tried all the three options, but unfortunately only the option A (Embed with CocoaPods and the Flutter SDK) worked, and it's the only option that I can't use, because it'll expose my source-code (which I can't). Currently I've tried to minimize the code, but still not working properly.

2021-04-15 19:12:55.694052-0300 libertyModuleIOS[78482:2330559] Failed to find snapshot: /Users/user/Library/Developer/CoreSimulator/Devices/34DB7C2C-0AF9-4F97-B94A-125550BB4806/data/Containers/Bundle/Application/8623C44A-A239-44C7-8474-5765E77BD28B/libertyModuleIOS.app/Frameworks/App.framework/flutter_assets/kernel_blob.bin
2021-04-15 19:12:55.694815-0300 libertyModuleIOS[78482:2330559] Metal API Validation Enabled
2021-04-15 19:12:55.772496-0300 libertyModuleIOS[78482:2331070] [VERBOSE-2:engine.cc(182)] Engine run configuration was invalid.
2021-04-15 19:12:55.772980-0300 libertyModuleIOS[78482:2331070] [VERBOSE-2:shell.cc(571)] Could not launch engine with configuration.
2021-04-15 19:12:56.148194-0300 libertyModuleIOS[78482:2331083] flutter: Observatory listening on http://127.0.0.1:57253/9vJInMBBG9w=/

The funny thing about that is, on my physical device (Iphone SE) it works perfectly, but when I upload it to TestFlight or try to run it on the emulator (even on iPhone SE), it doesn't work, and show the error above (only on emulator, of course). And by the way, I don't use CocoaPods to generate the code (I've already tried using it with the third option, but "came out" the same problem).

The Swift code I'm using is the exact same on the Flutter documentation.


AppDelegate.swift

import UIKit
import Flutter
// Used to connect plugins (only if you have plugins with iOS platform code).
import FlutterPluginRegistrant

@UIApplicationMain
class AppDelegate: FlutterAppDelegate { // More on the FlutterAppDelegate.
  lazy var flutterEngine = FlutterEngine(name: "my flutter engine")

  override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Runs the default Dart entrypoint with a default Flutter route.
    flutterEngine.run();
    // Used to connect plugins (only if you have plugins with iOS platform code).
    GeneratedPluginRegistrant.register(with: self.flutterEngine);
    return super.application(application, didFinishLaunchingWithOptions: launchOptions);
  }
}


ViewController.swift

import UIKit
import Flutter

class ViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()

    // Make a button to call the showFlutter function when pressed.
    let button = UIButton(type:UIButton.ButtonType.custom)
    button.addTarget(self, action: #selector(showFlutter), for: .touchUpInside)
    button.setTitle("Show Flutter!", for: UIControl.State.normal)
    button.frame = CGRect(x: 80.0, y: 210.0, width: 160.0, height: 40.0)
    button.backgroundColor = UIColor.blue
    self.view.addSubview(button)
  }

  @objc func showFlutter() {
    let flutterEngine = (UIApplication.shared.delegate as! AppDelegate).flutterEngine
    let flutterViewController =
        FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
    present(flutterViewController, animated: true, completion: nil)
  }
}

0

There are 0 answers