Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
bd96a8f9
Unverified
Commit
bd96a8f9
authored
Apr 09, 2021
by
Alan Trope
Committed by
GitHub
Apr 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch errors during android plugin registration (#78964)
parent
0f8a7cb3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
plugins.dart
packages/flutter_tools/lib/src/plugins.dart
+11
-1
plugins_test.dart
packages/flutter_tools/test/general.shard/plugins_test.dart
+26
-0
No files found.
packages/flutter_tools/lib/src/plugins.dart
View file @
bd96a8f9
...
...
@@ -567,6 +567,7 @@ package io.flutter.plugins;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.flutter.Log;
import io.flutter.embedding.engine.FlutterEngine;
{{#needsShim}}
...
...
@@ -580,17 +581,26 @@ import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
*/
@Keep
public final class GeneratedPluginRegistrant {
private static final String TAG = "GeneratedPluginRegistrant";
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
{{#needsShim}}
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
{{/needsShim}}
{{#plugins}}
{{#supportsEmbeddingV2}}
try {
flutterEngine.getPlugins().add(new {{package}}.{{class}}());
} catch(Exception e) {
Log.e(TAG, "Error registering plugin {{name}}, {{package}}.{{class}}", e);
}
{{/supportsEmbeddingV2}}
{{^supportsEmbeddingV2}}
{{#supportsEmbeddingV1}}
try {
{{package}}.{{class}}.registerWith(shimPluginRegistry.registrarFor("{{package}}.{{class}}"));
} catch(Exception e) {
Log.e(TAG, "Error registering plugin {{name}}, {{package}}.{{class}}", e);
}
{{/supportsEmbeddingV1}}
{{/supportsEmbeddingV2}}
{{/plugins}}
...
...
packages/flutter_tools/test/general.shard/plugins_test.dart
View file @
bd96a8f9
...
...
@@ -823,6 +823,32 @@ dependencies:
XcodeProjectInterpreter:
()
=>
xcodeProjectInterpreter
,
});
testUsingContext
(
'Module using multiple old and new plugins should be wrapped with try catch'
,
()
async
{
when
(
flutterProject
.
isModule
).
thenReturn
(
true
);
when
(
androidProject
.
getEmbeddingVersion
()).
thenReturn
(
AndroidEmbeddingVersion
.
v2
);
createOldJavaPlugin
(
'abcplugin1'
);
createNewJavaPlugin1
();
await
injectPlugins
(
flutterProject
,
androidPlatform:
true
);
final
File
registrant
=
flutterProject
.
directory
.
childDirectory
(
fs
.
path
.
join
(
'android'
,
'app'
,
'src'
,
'main'
,
'java'
,
'io'
,
'flutter'
,
'plugins'
))
.
childFile
(
'GeneratedPluginRegistrant.java'
);
const
String
newPluginName
=
'flutterEngine.getPlugins().add(new plugin1.UseNewEmbedding());'
;
const
String
oldPluginName
=
'abcplugin1.UseOldEmbedding.registerWith(shimPluginRegistry.registrarFor("abcplugin1.UseOldEmbedding"));'
;
final
String
content
=
registrant
.
readAsStringSync
();
for
(
final
String
plugin
in
<
String
>[
newPluginName
,
oldPluginName
]){
expect
(
content
,
contains
(
plugin
));
expect
(
content
.
split
(
plugin
).
first
.
trim
().
endsWith
(
'try {'
),
isTrue
);
expect
(
content
.
split
(
plugin
).
last
.
trim
().
startsWith
(
'} catch(Exception e) {'
),
isTrue
);
}
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
XcodeProjectInterpreter:
()
=>
xcodeProjectInterpreter
,
});
testUsingContext
(
'Does not throw when AndroidManifest.xml is not found'
,
()
async
{
when
(
flutterProject
.
isModule
).
thenReturn
(
false
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment