Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] android: use FlutterEngineGroup for better perf #150

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.flutter.FlutterInjector;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.FlutterEngineGroup;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.EventChannel;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class FlutterIsolatePlugin implements FlutterPlugin, MethodCallHandler, S
private Queue<IsolateHolder> queuedIsolates;
private Map<String, IsolateHolder> activeIsolates;
private Context context;
private FlutterEngineGroup engineGroup;

private static void registerWithCustomRegistrant(io.flutter.embedding.engine.FlutterEngine flutterEngine) {
if (registrant == null) return;
Expand Down Expand Up @@ -94,6 +96,7 @@ public static void setCustomIsolateRegistrant(Class registrant) {

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
engineGroup = new FlutterEngineGroup(binding.getApplicationContext());
setupChannel(binding.getBinaryMessenger(), binding.getApplicationContext());
}

Expand All @@ -115,14 +118,13 @@ private void startNextIsolate() {

FlutterInjector.instance().flutterLoader().ensureInitializationComplete(context, null);

isolate.engine = new FlutterEngine(context);

FlutterCallbackInformation cbInfo = FlutterCallbackInformation.lookupCallbackInformation(isolate.entryPoint);
FlutterRunArguments runArgs = new FlutterRunArguments();

runArgs.bundlePath = FlutterInjector.instance().flutterLoader().findAppBundlePath();
runArgs.libraryPath = cbInfo.callbackLibraryPath;
runArgs.entrypoint = cbInfo.callbackName;
isolate.engine = engineGroup.createAndRunEngine(context, new DartExecutor.DartEntrypoint(
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
cbInfo.callbackLibraryPath,
cbInfo.callbackName
));

isolate.controlChannel = new MethodChannel(isolate.engine.getDartExecutor().getBinaryMessenger(), NAMESPACE + "/control");
isolate.startupChannel = new EventChannel(isolate.engine.getDartExecutor().getBinaryMessenger(), NAMESPACE + "/event");
Expand All @@ -133,9 +135,6 @@ private void startNextIsolate() {
if (registrant != null) {
registerWithCustomRegistrant(isolate.engine);
}

DartExecutor.DartCallback dartCallback = new DartExecutor.DartCallback(context.getAssets(), runArgs.bundlePath, cbInfo);
isolate.engine.getDartExecutor().executeDartCallback(dartCallback);
}

@Override
Expand Down