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
b94c1a41
Commit
b94c1a41
authored
Nov 04, 2019
by
Emmanuel Garcia
Committed by
Jonah Williams
Nov 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exit tool if a plugin supports the embedding v2 but the app doesn't (#44026)
parent
97cf355b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
137 additions
and
12 deletions
+137
-12
platform_plugins.dart
packages/flutter_tools/lib/src/platform_plugins.dart
+15
-6
plugins.dart
packages/flutter_tools/lib/src/plugins.dart
+17
-6
plugins_test.dart
packages/flutter_tools/test/general.shard/plugins_test.dart
+105
-0
No files found.
packages/flutter_tools/lib/src/platform_plugins.dart
View file @
b94c1a41
...
...
@@ -64,17 +64,20 @@ class AndroidPlugin extends PluginPlatform {
'name'
:
name
,
'package'
:
package
,
'class'
:
pluginClass
,
'usesEmbedding2'
:
_embeddingVersion
==
'2'
,
// Mustache doesn't support complex types.
'supportsEmbeddingV1'
:
_supportedEmbedings
.
contains
(
'1'
),
'supportsEmbeddingV2'
:
_supportedEmbedings
.
contains
(
'2'
),
};
}
S
tring
_cachedEmbeddingVersion
;
S
et
<
String
>
_cachedEmbeddingVersion
;
/// Returns the version of the Android embedding.
S
tring
get
_embeddingVersion
=>
_cachedEmbeddingVersion
??=
_getEmbeddingVersion
();
S
et
<
String
>
get
_supportedEmbedings
=>
_cachedEmbeddingVersion
??=
_getSupportedEmbeddings
();
S
tring
_getEmbeddingVersion
()
{
S
et
<
String
>
_getSupportedEmbeddings
()
{
assert
(
pluginPath
!=
null
);
final
Set
<
String
>
supportedEmbeddings
=
<
String
>{};
final
String
baseMainPath
=
fs
.
path
.
join
(
pluginPath
,
'android'
,
...
...
@@ -113,9 +116,15 @@ class AndroidPlugin extends PluginPlatform {
}
if
(
mainClassContent
.
contains
(
'io.flutter.embedding.engine.plugins.FlutterPlugin'
))
{
return
'2'
;
supportedEmbeddings
.
add
(
'2'
);
}
else
{
supportedEmbeddings
.
add
(
'1'
);
}
return
'1'
;
if
(
mainClassContent
.
contains
(
'registerWith(Registrar registrar)'
)
||
mainClassContent
.
contains
(
'registerWith(registrar: Registrar)'
))
{
supportedEmbeddings
.
add
(
'1'
);
}
return
supportedEmbeddings
;
}
}
...
...
packages/flutter_tools/lib/src/plugins.dart
View file @
b94c1a41
...
...
@@ -338,12 +338,14 @@ public final class GeneratedPluginRegistrant {
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
{{/needsShim}}
{{#plugins}}
{{#
usesEmbedding
2}}
{{#
supportsEmbeddingV
2}}
flutterEngine.getPlugins().add(new {{package}}.{{class}}());
{{/usesEmbedding2}}
{{^usesEmbedding2}}
{{package}}.{{class}}.registerWith(shimPluginRegistry.registrarFor("{{package}}.{{class}}"));
{{/usesEmbedding2}}
{{/supportsEmbeddingV2}}
{{^supportsEmbeddingV2}}
{{#supportsEmbeddingV1}}
{{package}}.{{class}}.registerWith(shimPluginRegistry.registrarFor("{{package}}.{{class}}"));
{{/supportsEmbeddingV1}}
{{/supportsEmbeddingV2}}
{{/plugins}}
}
}
...
...
@@ -417,7 +419,7 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
// If a plugin is using an embedding version older than 2.0 and the app is using 2.0,
// then add shim for the old plugins.
for
(
Map
<
String
,
dynamic
>
plugin
in
androidPlugins
)
{
if
(
!
plugin
[
'usesEmbedding
2'
])
{
if
(
plugin
[
'supportsEmbeddingV1'
]
&&
!
plugin
[
'supportsEmbeddingV
2'
])
{
templateContext
[
'needsShim'
]
=
true
;
break
;
}
...
...
@@ -425,6 +427,15 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
templateContent
=
_androidPluginRegistryTemplateNewEmbedding
;
break
;
case
'1'
:
for
(
Map
<
String
,
dynamic
>
plugin
in
androidPlugins
)
{
if
(!
plugin
[
'supportsEmbeddingV1'
]
&&
plugin
[
'supportsEmbeddingV2'
])
{
throwToolExit
(
'The plugin `
${plugin['name']}
` requires your app to be migrated to '
'the Android embedding v2. Follow the steps on https://flutter.dev/go/android-project-migration '
'and re-run this command.'
);
}
}
templateContent
=
_androidPluginRegistryTemplateOldEmbedding
;
break
;
default
:
...
...
packages/flutter_tools/test/general.shard/plugins_test.dart
View file @
b94c1a41
...
...
@@ -299,6 +299,111 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()}
XcodeProjectInterpreter:
()
=>
xcodeProjectInterpreter
,
});
testUsingContext
(
'exits the tool if an app uses the v1 embedding and a plugin only supports the v2 embedding'
,
()
async
{
when
(
flutterProject
.
isModule
).
thenReturn
(
false
);
final
File
androidManifest
=
flutterProject
.
directory
.
childDirectory
(
'android'
)
.
childFile
(
'AndroidManifest.xml'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
kAndroidManifestUsingOldEmbedding
);
when
(
androidProject
.
appManifestFile
).
thenReturn
(
androidManifest
);
final
Directory
pluginUsingJavaAndNewEmbeddingDir
=
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_plugin_using_java_and_new_embedding_dir.'
);
pluginUsingJavaAndNewEmbeddingDir
.
childFile
(
'pubspec.yaml'
)
.
writeAsStringSync
(
'''
flutter:
plugin:
androidPackage: plugin1
pluginClass: UseNewEmbedding
'''
);
pluginUsingJavaAndNewEmbeddingDir
.
childDirectory
(
'android'
)
.
childDirectory
(
'src'
)
.
childDirectory
(
'main'
)
.
childDirectory
(
'java'
)
.
childDirectory
(
'plugin1'
)
.
childFile
(
'UseNewEmbedding.java'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'import io.flutter.embedding.engine.plugins.FlutterPlugin;'
);
flutterProject
.
directory
.
childFile
(
'.packages'
)
.
writeAsStringSync
(
'''
plugin1:
${pluginUsingJavaAndNewEmbeddingDir.childDirectory('lib').uri.toString()}
'''
);
await
expectLater
(
()
async
{
await
injectPlugins
(
flutterProject
);
},
throwsToolExit
(
message:
'The plugin `plugin1` requires your app to be migrated to the Android embedding v2. '
'Follow the steps on https://flutter.dev/go/android-project-migration and re-run this command.'
),
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
FeatureFlags:
()
=>
featureFlags
,
XcodeProjectInterpreter:
()
=>
xcodeProjectInterpreter
,
});
testUsingContext
(
'allows app use a plugin that supports v1 and v2 embedding'
,
()
async
{
when
(
flutterProject
.
isModule
).
thenReturn
(
false
);
final
File
androidManifest
=
flutterProject
.
directory
.
childDirectory
(
'android'
)
.
childFile
(
'AndroidManifest.xml'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
kAndroidManifestUsingOldEmbedding
);
when
(
androidProject
.
appManifestFile
).
thenReturn
(
androidManifest
);
final
Directory
pluginUsingJavaAndNewEmbeddingDir
=
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_plugin_using_java_and_new_embedding_dir.'
);
pluginUsingJavaAndNewEmbeddingDir
.
childFile
(
'pubspec.yaml'
)
.
writeAsStringSync
(
'''
flutter:
plugin:
androidPackage: plugin1
pluginClass: UseNewEmbedding
'''
);
pluginUsingJavaAndNewEmbeddingDir
.
childDirectory
(
'android'
)
.
childDirectory
(
'src'
)
.
childDirectory
(
'main'
)
.
childDirectory
(
'java'
)
.
childDirectory
(
'plugin1'
)
.
childFile
(
'UseNewEmbedding.java'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'import io.flutter.embedding.engine.plugins.FlutterPlugin;'
'registerWith(Registrar registrar)'
);
flutterProject
.
directory
.
childFile
(
'.packages'
)
.
writeAsStringSync
(
'''
plugin1:
${pluginUsingJavaAndNewEmbeddingDir.childDirectory('lib').uri.toString()}
'''
);
await
injectPlugins
(
flutterProject
);
final
File
registrant
=
flutterProject
.
directory
.
childDirectory
(
fs
.
path
.
join
(
'android'
,
'app'
,
'src'
,
'main'
,
'java'
,
'io'
,
'flutter'
,
'plugins'
))
.
childFile
(
'GeneratedPluginRegistrant.java'
);
expect
(
registrant
.
existsSync
(),
isTrue
);
expect
(
registrant
.
readAsStringSync
(),
contains
(
'package io.flutter.plugins'
));
expect
(
registrant
.
readAsStringSync
(),
contains
(
'class GeneratedPluginRegistrant'
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
FeatureFlags:
()
=>
featureFlags
,
XcodeProjectInterpreter:
()
=>
xcodeProjectInterpreter
,
});
testUsingContext
(
'Registrant doesn
\'
t use new embedding if app doesn
\'
t use new embedding'
,
()
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