forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto plugin registration to FlutterFragmentActivity as well (flut…
- Loading branch information
Showing
6 changed files
with
110 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
shell/platform/android/io/flutter/embedding/engine/plugins/util/GeneratedPluginRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.embedding.engine.plugins.util; | ||
|
||
import androidx.annotation.NonNull; | ||
import io.flutter.Log; | ||
import io.flutter.embedding.engine.FlutterEngine; | ||
import java.lang.reflect.Method; | ||
|
||
public class GeneratedPluginRegister { | ||
private static final String TAG = "GeneratedPluginsRegister"; | ||
/** | ||
* Registers all plugins that an app lists in its pubspec.yaml. | ||
* | ||
* <p>The Flutter tool generates a class called GeneratedPluginRegistrant, which includes the code | ||
* necessary to register every plugin in the pubspec.yaml with a given {@code FlutterEngine}. The | ||
* GeneratedPluginRegistrant must be generated per app, because each app uses different sets of | ||
* plugins. Therefore, the Android embedding cannot place a compile-time dependency on this | ||
* generated class. This method uses reflection to attempt to locate the generated file and then | ||
* use it at runtime. | ||
* | ||
* <p>This method fizzles if the GeneratedPluginRegistrant cannot be found or invoked. This | ||
* situation should never occur, but if any eventuality comes up that prevents an app from using | ||
* this behavior, that app can still write code that explicitly registers plugins. | ||
*/ | ||
public static void registerGeneratedPlugins(@NonNull FlutterEngine flutterEngine) { | ||
try { | ||
Class<?> generatedPluginRegistrant = | ||
Class.forName("io.flutter.plugins.GeneratedPluginRegistrant"); | ||
Method registrationMethod = | ||
generatedPluginRegistrant.getDeclaredMethod("registerWith", FlutterEngine.class); | ||
registrationMethod.invoke(null, flutterEngine); | ||
} catch (Exception e) { | ||
Log.w( | ||
TAG, | ||
"Tried to automatically register plugins with FlutterEngine (" | ||
+ flutterEngine | ||
+ ") but could not find and invoke the GeneratedPluginRegistrant."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters