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
cf95cd43
Unverified
Commit
cf95cd43
authored
Nov 06, 2019
by
xster
Committed by
GitHub
Nov 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add v1 plugin register function into v2 plugin template (#44166)
parent
7aebde19
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
6 deletions
+55
-6
plugin_test.dart
dev/devicelab/bin/tasks/plugin_test.dart
+7
-0
utils.dart
dev/devicelab/lib/framework/utils.dart
+2
-1
plugin_tests.dart
dev/devicelab/lib/tasks/plugin_tests.dart
+13
-5
pluginClass.java.tmpl
...mpl/src/main/java/androidIdentifier/pluginClass.java.tmpl
+15
-0
pluginClass.kt.tmpl
...mpl/src/main/kotlin/androidIdentifier/pluginClass.kt.tmpl
+18
-0
No files found.
dev/devicelab/bin/tasks/plugin_test.dart
View file @
cf95cd43
...
...
@@ -11,5 +11,12 @@ Future<void> main() async {
await
task
(
combine
(<
TaskFunction
>[
PluginTest
(
'apk'
,
<
String
>[
'-a'
,
'java'
]),
PluginTest
(
'apk'
,
<
String
>[
'-a'
,
'kotlin'
]),
// These create the plugins using the new v2 plugin templates but create the
// apps using the old v1 embedding app templates to make sure new plugins
// are by default backward compatible.
PluginTest
(
'apk'
,
<
String
>[
'-a'
,
'java'
],
pluginCreateEnvironment:
<
String
,
String
>{
'ENABLE_ANDROID_EMBEDDING_V2'
:
'true'
}),
PluginTest
(
'apk'
,
<
String
>[
'-a'
,
'kotlin'
],
pluginCreateEnvironment:
<
String
,
String
>{
'ENABLE_ANDROID_EMBEDDING_V2'
:
'true'
}),
]));
}
dev/devicelab/lib/framework/utils.dart
View file @
cf95cd43
...
...
@@ -256,7 +256,8 @@ Future<Process> startProcess(
assert
(
isBot
!=
null
);
final
String
command
=
'
$executable
${arguments?.join(" ") ?? ""}
'
;
final
String
finalWorkingDirectory
=
workingDirectory
??
cwd
;
print
(
'
\n
Executing:
$command
in
$finalWorkingDirectory
'
);
print
(
'
\n
Executing:
$command
in
$finalWorkingDirectory
'
+
(
environment
!=
null
?
' with environment
$environment
'
:
''
));
environment
??=
<
String
,
String
>{};
environment
[
'BOT'
]
=
isBot
?
'true'
:
'false'
;
final
Process
process
=
await
_processManager
.
start
(
...
...
dev/devicelab/lib/tasks/plugin_tests.dart
View file @
cf95cd43
...
...
@@ -26,10 +26,12 @@ TaskFunction combine(List<TaskFunction> tasks) {
/// Defines task that creates new Flutter project, adds a local and remote
/// plugin, and then builds the specified [buildTarget].
class
PluginTest
{
PluginTest
(
this
.
buildTarget
,
this
.
options
);
PluginTest
(
this
.
buildTarget
,
this
.
options
,
{
this
.
pluginCreateEnvironment
,
this
.
appCreateEnvironment
}
);
final
String
buildTarget
;
final
List
<
String
>
options
;
final
Map
<
String
,
String
>
pluginCreateEnvironment
;
final
Map
<
String
,
String
>
appCreateEnvironment
;
Future
<
TaskResult
>
call
()
async
{
final
Directory
tempDir
=
...
...
@@ -38,12 +40,12 @@ class PluginTest {
section
(
'Create plugin'
);
final
_FlutterProject
plugin
=
await
_FlutterProject
.
create
(
tempDir
,
options
,
name:
'plugintest'
,
template:
'plugin'
);
name:
'plugintest'
,
template:
'plugin'
,
environment:
pluginCreateEnvironment
);
section
(
'Test plugin'
);
await
plugin
.
test
();
section
(
'Create Flutter app'
);
final
_FlutterProject
app
=
await
_FlutterProject
.
create
(
tempDir
,
options
,
name:
'plugintestapp'
,
template:
'app'
);
name:
'plugintestapp'
,
template:
'app'
,
environment:
appCreateEnvironment
);
try
{
if
(
buildTarget
==
'ios'
)
await
prepareProvisioningCertificates
(
app
.
rootPath
);
...
...
@@ -95,8 +97,13 @@ class _FlutterProject {
}
static
Future
<
_FlutterProject
>
create
(
Directory
directory
,
List
<
String
>
options
,
{
String
name
,
String
template
})
async
{
Directory
directory
,
List
<
String
>
options
,
{
String
name
,
String
template
,
Map
<
String
,
String
>
environment
,
})
async
{
await
inDirectory
(
directory
,
()
async
{
await
flutter
(
'create'
,
...
...
@@ -107,6 +114,7 @@ class _FlutterProject {
...
options
,
name
,
],
environment:
environment
,
);
});
return
_FlutterProject
(
directory
,
name
);
...
...
packages/flutter_tools/templates/plugin/android-java.tmpl/src/main/java/androidIdentifier/pluginClass.java.tmpl
View file @
cf95cd43
...
...
@@ -12,6 +12,7 @@ import io.flutter.plugin.common.MethodCall;
import
io
.
flutter
.
plugin
.
common
.
MethodChannel
;
import
io
.
flutter
.
plugin
.
common
.
MethodChannel
.
MethodCallHandler
;
import
io
.
flutter
.
plugin
.
common
.
MethodChannel
.
Result
;
import
io
.
flutter
.
plugin
.
common
.
PluginRegistry
.
Registrar
;
/**
{{
pluginClass
}}
*/
public
class
{{
pluginClass
}}
implements
FlutterPlugin
,
MethodCallHandler
{
...
...
@@ -21,6 +22,20 @@ public class {{pluginClass}} implements FlutterPlugin, MethodCallHandler {
channel
.
setMethodCallHandler
(
new
{{
pluginClass
}}());
}
//
This
static
function
is
optional
and
equivalent
to
onAttachedToEngine
.
It
supports
the
old
//
pre
-
Flutter
-
1.12
Android
projects
.
You
are
encouraged
to
continue
supporting
//
plugin
registration
via
this
function
while
apps
migrate
to
use
the
new
Android
APIs
//
post
-
flutter
-
1.12
via
https
://
flutter
.
dev
/
go
/
android
-
project
-
migration
.
//
//
It
is
encouraged
to
share
logic
between
onAttachedToEngine
and
registerWith
to
keep
//
them
functionally
equivalent
.
Only
one
of
onAttachedToEngine
or
registerWith
will
be
called
//
depending
on
the
user
's project. onAttachedToEngine or registerWith must both be defined
// in the same class.
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "{{projectName}}");
channel.setMethodCallHandler(new {{pluginClass}}());
}
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
if (call.method.equals("getPlatformVersion")) {
...
...
packages/flutter_tools/templates/plugin/android-kotlin.tmpl/src/main/kotlin/androidIdentifier/pluginClass.kt.tmpl
View file @
cf95cd43
...
...
@@ -12,6 +12,7 @@ import io.flutter.plugin.common.MethodCall
import
io
.
flutter
.
plugin
.
common
.
MethodChannel
import
io
.
flutter
.
plugin
.
common
.
MethodChannel
.
MethodCallHandler
import
io
.
flutter
.
plugin
.
common
.
MethodChannel
.
Result
import
io
.
flutter
.
plugin
.
common
.
PluginRegistry
.
Registrar
/**
{{
pluginClass
}}
*/
public
class
{{
pluginClass
}}:
FlutterPlugin
,
MethodCallHandler
{
...
...
@@ -20,6 +21,23 @@ public class {{pluginClass}}: FlutterPlugin, MethodCallHandler {
channel
.
setMethodCallHandler
({{
pluginClass
}}());
}
//
This
static
function
is
optional
and
equivalent
to
onAttachedToEngine
.
It
supports
the
old
//
pre
-
Flutter
-
1.12
Android
projects
.
You
are
encouraged
to
continue
supporting
//
plugin
registration
via
this
function
while
apps
migrate
to
use
the
new
Android
APIs
//
post
-
flutter
-
1.12
via
https
://
flutter
.
dev
/
go
/
android
-
project
-
migration
.
//
//
It
is
encouraged
to
share
logic
between
onAttachedToEngine
and
registerWith
to
keep
//
them
functionally
equivalent
.
Only
one
of
onAttachedToEngine
or
registerWith
will
be
called
//
depending
on
the
user
's project. onAttachedToEngine or registerWith must both be defined
// in the same class.
companion object {
@JvmStatic
fun registerWith(registrar: Registrar) {
val channel = MethodChannel(registrar.messenger(), "{{projectName}}")
channel.setMethodCallHandler({{pluginClass}}())
}
}
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
...
...
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