Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
81c2c811
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
81c2c811
编写于
4月 02, 2021
作者:
J
Jim Graham
提交者:
GitHub
4月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "Deduplicate plugin registration logic and make error logs visible (#25297)"
This reverts commit
443e6275
.
上级
ea206e23
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
47 deletion
+45
-47
shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java
...rm/android/io/flutter/embedding/engine/FlutterEngine.java
+32
-2
shell/platform/android/io/flutter/embedding/engine/plugins/util/GeneratedPluginRegister.java
...mbedding/engine/plugins/util/GeneratedPluginRegister.java
+1
-5
shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineTest.java
...d/test/io/flutter/embedding/engine/FlutterEngineTest.java
+12
-36
shell/platform/android/test/io/flutter/plugins/GeneratedPluginRegistrant.java
...id/test/io/flutter/plugins/GeneratedPluginRegistrant.java
+0
-4
未找到文件。
shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java
浏览文件 @
81c2c811
...
...
@@ -20,7 +20,6 @@ import io.flutter.embedding.engine.plugins.activity.ActivityControlSurface;
import
io.flutter.embedding.engine.plugins.broadcastreceiver.BroadcastReceiverControlSurface
;
import
io.flutter.embedding.engine.plugins.contentprovider.ContentProviderControlSurface
;
import
io.flutter.embedding.engine.plugins.service.ServiceControlSurface
;
import
io.flutter.embedding.engine.plugins.util.GeneratedPluginRegister
;
import
io.flutter.embedding.engine.renderer.FlutterRenderer
;
import
io.flutter.embedding.engine.renderer.RenderSurface
;
import
io.flutter.embedding.engine.systemchannels.AccessibilityChannel
;
...
...
@@ -37,6 +36,7 @@ import io.flutter.embedding.engine.systemchannels.SystemChannel;
import
io.flutter.embedding.engine.systemchannels.TextInputChannel
;
import
io.flutter.plugin.localization.LocalizationPlugin
;
import
io.flutter.plugin.platform.PlatformViewsController
;
import
java.lang.reflect.Method
;
import
java.util.HashSet
;
import
java.util.Set
;
...
...
@@ -342,7 +342,7 @@ public class FlutterEngine {
// Only automatically register plugins if both constructor parameter and
// loaded AndroidManifest config turn this feature on.
if
(
automaticallyRegisterPlugins
&&
flutterLoader
.
automaticallyRegisterPlugins
())
{
GeneratedPluginRegister
.
registerGeneratedPlugins
(
this
);
registerPlugins
(
);
}
}
...
...
@@ -391,6 +391,36 @@ public class FlutterEngine {
newFlutterJNI
);
// FlutterJNI.
}
/**
* 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.
*/
private
void
registerPlugins
()
{
try
{
Class
<?>
generatedPluginRegistrant
=
Class
.
forName
(
"io.flutter.plugins.GeneratedPluginRegistrant"
);
Method
registrationMethod
=
generatedPluginRegistrant
.
getDeclaredMethod
(
"registerWith"
,
FlutterEngine
.
class
);
registrationMethod
.
invoke
(
null
,
this
);
}
catch
(
Exception
e
)
{
Log
.
w
(
TAG
,
"Tried to automatically register plugins with FlutterEngine ("
+
this
+
") but could not find and invoke the GeneratedPluginRegistrant."
);
}
}
/**
* Cleans up all components within this {@code FlutterEngine} and destroys the associated Dart
* Isolate. All state held by the Dart Isolate, such as the Flutter Elements tree, is lost.
...
...
shell/platform/android/io/flutter/embedding/engine/plugins/util/GeneratedPluginRegister.java
浏览文件 @
81c2c811
...
...
@@ -33,15 +33,11 @@ public class GeneratedPluginRegister {
generatedPluginRegistrant
.
getDeclaredMethod
(
"registerWith"
,
FlutterEngine
.
class
);
registrationMethod
.
invoke
(
null
,
flutterEngine
);
}
catch
(
Exception
e
)
{
Log
.
e
(
Log
.
w
(
TAG
,
"Tried to automatically register plugins with FlutterEngine ("
+
flutterEngine
+
") but could not find and invoke the GeneratedPluginRegistrant."
);
Log
.
e
(
TAG
,
// getCause here because the first layer of the exception would be from reflect.
"Received exception while registering: "
+
e
.
getCause
());
}
}
}
shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineTest.java
浏览文件 @
81c2c811
...
...
@@ -35,7 +35,6 @@ import org.mockito.stubbing.Answer;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.RuntimeEnvironment
;
import
org.robolectric.annotation.Config
;
import
org.robolectric.shadows.ShadowLog
;
@Config
(
manifest
=
Config
.
NONE
)
@RunWith
(
RobolectricTestRunner
.
class
)
...
...
@@ -64,9 +63,6 @@ public class FlutterEngineTest {
@After
public
void
tearDown
()
{
GeneratedPluginRegistrant
.
clearRegisteredEngines
();
// Make sure to not forget to remove the mock exception in the generated plugin registration
// mock, or everything subsequent will break.
GeneratedPluginRegistrant
.
pluginRegistrationException
=
null
;
}
@Test
...
...
@@ -82,38 +78,6 @@ public class FlutterEngineTest {
assertEquals
(
flutterEngine
,
registeredEngines
.
get
(
0
));
}
// Helps show the root cause of MissingPluginException type errors like
// https://github.com/flutter/flutter/issues/78625.
@Test
public
void
itCatchesAndDisplaysRegistrationExceptions
()
{
assertTrue
(
GeneratedPluginRegistrant
.
getRegisteredEngines
().
isEmpty
());
GeneratedPluginRegistrant
.
pluginRegistrationException
=
new
RuntimeException
(
"I'm a bug in the plugin"
);
FlutterLoader
mockFlutterLoader
=
mock
(
FlutterLoader
.
class
);
when
(
mockFlutterLoader
.
automaticallyRegisterPlugins
()).
thenReturn
(
true
);
FlutterEngine
flutterEngine
=
new
FlutterEngine
(
RuntimeEnvironment
.
application
,
mockFlutterLoader
,
flutterJNI
);
List
<
FlutterEngine
>
registeredEngines
=
GeneratedPluginRegistrant
.
getRegisteredEngines
();
// When it crashes, it doesn't end up registering anything.
assertEquals
(
0
,
registeredEngines
.
size
());
// Check the logs actually says registration failed, so a subsequent MissingPluginException
// isn't mysterious.
assertTrue
(
ShadowLog
.
getLogsForTag
(
"GeneratedPluginsRegister"
)
.
get
(
0
)
.
msg
.
contains
(
"Tried to automatically register plugins"
));
assertTrue
(
ShadowLog
.
getLogsForTag
(
"GeneratedPluginsRegister"
)
.
get
(
1
)
.
msg
.
contains
(
"I'm a bug in the plugin"
));
GeneratedPluginRegistrant
.
pluginRegistrationException
=
null
;
}
@Test
public
void
itDoesNotAutomaticallyRegistersPluginsWhenFlutterLoaderDisablesIt
()
{
assertTrue
(
GeneratedPluginRegistrant
.
getRegisteredEngines
().
isEmpty
());
...
...
@@ -141,6 +105,18 @@ public class FlutterEngineTest {
assertTrue
(
registeredEngines
.
isEmpty
());
}
@Test
public
void
itCanBeConfiguredToNotAutomaticallyRegisterPlugins
()
{
new
FlutterEngine
(
RuntimeEnvironment
.
application
,
mock
(
FlutterLoader
.
class
),
flutterJNI
,
/*dartVmArgs=*/
new
String
[]
{},
/*automaticallyRegisterPlugins=*/
false
);
assertTrue
(
GeneratedPluginRegistrant
.
getRegisteredEngines
().
isEmpty
());
}
@Test
public
void
itNotifiesPlatformViewsControllerWhenDevHotRestart
()
{
// Setup test.
...
...
shell/platform/android/test/io/flutter/plugins/GeneratedPluginRegistrant.java
浏览文件 @
81c2c811
...
...
@@ -13,7 +13,6 @@ import java.util.List;
@VisibleForTesting
public
class
GeneratedPluginRegistrant
{
private
static
final
List
<
FlutterEngine
>
registeredEngines
=
new
ArrayList
<>();
public
static
RuntimeException
pluginRegistrationException
;
/**
* The one and only method currently generated by the tool.
...
...
@@ -22,9 +21,6 @@ public class GeneratedPluginRegistrant {
* all registered engines instead.
*/
public
static
void
registerWith
(
FlutterEngine
engine
)
{
if
(
pluginRegistrationException
!=
null
)
{
throw
pluginRegistrationException
;
}
registeredEngines
.
add
(
engine
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录