Unverified Commit ade8dfac authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Move the plugin registrant to io.flutter.plugins and add the @Keep annotation (#44011)

parent 93ab9e64
package com.example.android_embedding_v2_smoke_test package com.example.android_embedding_v2_smoke_test
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() { class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
......
package io.flutter.add2app; package io.flutter.add2app;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity { public class MainActivity extends FlutterActivity {
@Override @Override
......
package io.flutter.add2app; package io.flutter.add2app;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity { public class MainActivity extends FlutterActivity {
@Override @Override
......
package io.flutter.add2app; package io.flutter.add2app;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity { public class MainActivity extends FlutterActivity {
@Override @Override
......
...@@ -311,12 +311,14 @@ public final class GeneratedPluginRegistrant { ...@@ -311,12 +311,14 @@ public final class GeneratedPluginRegistrant {
} }
'''; ''';
const String _androidPluginRegistryTemplateNewEmbedding = '''package dev.flutter.plugins; const String _androidPluginRegistryTemplateNewEmbedding = '''package io.flutter.plugins;
{{#androidX}} {{#androidX}}
import androidx.annotation.Keep;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
{{/androidX}} {{/androidX}}
{{^androidX}} {{^androidX}}
import android.support.annotation.Keep;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
{{/androidX}} {{/androidX}}
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
...@@ -329,6 +331,7 @@ import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry; ...@@ -329,6 +331,7 @@ import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
* This file is generated by the Flutter tool based on the * This file is generated by the Flutter tool based on the
* plugins that support the Android platform. * plugins that support the Android platform.
*/ */
@Keep
public final class GeneratedPluginRegistrant { public final class GeneratedPluginRegistrant {
public static void registerWith(@NonNull FlutterEngine flutterEngine) { public static void registerWith(@NonNull FlutterEngine flutterEngine) {
{{#needsShim}} {{#needsShim}}
...@@ -399,10 +402,14 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin> ...@@ -399,10 +402,14 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
'main', 'main',
'java', 'java',
); );
final String registryPath = fs.path.join(
String registryPath; javaSourcePath,
'io',
'flutter',
'plugins',
'GeneratedPluginRegistrant.java',
);
String templateContent; String templateContent;
final String appEmbeddingVersion = _getAndroidEmbeddingVersion(project); final String appEmbeddingVersion = _getAndroidEmbeddingVersion(project);
switch (appEmbeddingVersion) { switch (appEmbeddingVersion) {
case '2': case '2':
...@@ -415,23 +422,9 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin> ...@@ -415,23 +422,9 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
break; break;
} }
} }
registryPath = fs.path.join(
javaSourcePath,
'dev',
'flutter',
'plugins',
'GeneratedPluginRegistrant.java',
);
templateContent = _androidPluginRegistryTemplateNewEmbedding; templateContent = _androidPluginRegistryTemplateNewEmbedding;
break; break;
case '1': case '1':
registryPath = fs.path.join(
javaSourcePath,
'io',
'flutter',
'plugins',
'GeneratedPluginRegistrant.java',
);
templateContent = _androidPluginRegistryTemplateOldEmbedding; templateContent = _androidPluginRegistryTemplateOldEmbedding;
break; break;
default: default:
......
...@@ -7,9 +7,9 @@ import androidx.annotation.NonNull; ...@@ -7,9 +7,9 @@ import androidx.annotation.NonNull;
{{^androidX}} {{^androidX}}
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
{{/androidX}} {{/androidX}}
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity { public class MainActivity extends FlutterActivity {
@Override @Override
......
...@@ -7,9 +7,9 @@ import androidx.annotation.NonNull; ...@@ -7,9 +7,9 @@ import androidx.annotation.NonNull;
{{^androidX}} {{^androidX}}
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
{{/androidX}} {{/androidX}}
import dev.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() { class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
......
...@@ -8,9 +8,9 @@ import androidx.annotation.NonNull; ...@@ -8,9 +8,9 @@ import androidx.annotation.NonNull;
{{^androidX}} {{^androidX}}
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
{{/androidX}} {{/androidX}}
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity { public class MainActivity extends FlutterActivity {
@Override @Override
......
...@@ -190,11 +190,11 @@ void main() { ...@@ -190,11 +190,11 @@ void main() {
await injectPlugins(flutterProject); await injectPlugins(flutterProject);
final File registrant = flutterProject.directory final File registrant = flutterProject.directory
.childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'dev', 'flutter', 'plugins')) .childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'io', 'flutter', 'plugins'))
.childFile('GeneratedPluginRegistrant.java'); .childFile('GeneratedPluginRegistrant.java');
expect(registrant.existsSync(), isTrue); expect(registrant.existsSync(), isTrue);
expect(registrant.readAsStringSync(), contains('package dev.flutter.plugins')); expect(registrant.readAsStringSync(), contains('package io.flutter.plugins'));
expect(registrant.readAsStringSync(), contains('class GeneratedPluginRegistrant')); expect(registrant.readAsStringSync(), contains('class GeneratedPluginRegistrant'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fs, FileSystem: () => fs,
...@@ -282,7 +282,7 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()} ...@@ -282,7 +282,7 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()}
await injectPlugins(flutterProject); await injectPlugins(flutterProject);
final File registrant = flutterProject.directory final File registrant = flutterProject.directory
.childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'dev', 'flutter', 'plugins')) .childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'io', 'flutter', 'plugins'))
.childFile('GeneratedPluginRegistrant.java'); .childFile('GeneratedPluginRegistrant.java');
expect(registrant.readAsStringSync(), expect(registrant.readAsStringSync(),
...@@ -362,11 +362,11 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()} ...@@ -362,11 +362,11 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()}
await injectPlugins(flutterProject); await injectPlugins(flutterProject);
final File registrant = flutterProject.directory final File registrant = flutterProject.directory
.childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'dev', 'flutter', 'plugins')) .childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'io', 'flutter', 'plugins'))
.childFile('GeneratedPluginRegistrant.java'); .childFile('GeneratedPluginRegistrant.java');
expect(registrant.existsSync(), isTrue); expect(registrant.existsSync(), isTrue);
expect(registrant.readAsStringSync(), contains('package dev.flutter.plugins')); expect(registrant.readAsStringSync(), contains('package io.flutter.plugins'));
expect(registrant.readAsStringSync(), contains('class GeneratedPluginRegistrant')); expect(registrant.readAsStringSync(), contains('class GeneratedPluginRegistrant'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fs, FileSystem: () => fs,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment