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
import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
......
package io.flutter.add2app;
import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
......
package io.flutter.add2app;
import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
......
package io.flutter.add2app;
import androidx.annotation.NonNull;
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
......
......@@ -311,12 +311,14 @@ public final class GeneratedPluginRegistrant {
}
''';
const String _androidPluginRegistryTemplateNewEmbedding = '''package dev.flutter.plugins;
const String _androidPluginRegistryTemplateNewEmbedding = '''package io.flutter.plugins;
{{#androidX}}
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
{{/androidX}}
{{^androidX}}
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
{{/androidX}}
import io.flutter.embedding.engine.FlutterEngine;
......@@ -329,6 +331,7 @@ import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
* This file is generated by the Flutter tool based on the
* plugins that support the Android platform.
*/
@Keep
public final class GeneratedPluginRegistrant {
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
{{#needsShim}}
......@@ -399,10 +402,14 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
'main',
'java',
);
String registryPath;
final String registryPath = fs.path.join(
javaSourcePath,
'io',
'flutter',
'plugins',
'GeneratedPluginRegistrant.java',
);
String templateContent;
final String appEmbeddingVersion = _getAndroidEmbeddingVersion(project);
switch (appEmbeddingVersion) {
case '2':
......@@ -415,23 +422,9 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
break;
}
}
registryPath = fs.path.join(
javaSourcePath,
'dev',
'flutter',
'plugins',
'GeneratedPluginRegistrant.java',
);
templateContent = _androidPluginRegistryTemplateNewEmbedding;
break;
case '1':
registryPath = fs.path.join(
javaSourcePath,
'io',
'flutter',
'plugins',
'GeneratedPluginRegistrant.java',
);
templateContent = _androidPluginRegistryTemplateOldEmbedding;
break;
default:
......
......@@ -7,9 +7,9 @@ import androidx.annotation.NonNull;
{{^androidX}}
import android.support.annotation.NonNull;
{{/androidX}}
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
......
......@@ -7,9 +7,9 @@ import androidx.annotation.NonNull;
{{^androidX}}
import android.support.annotation.NonNull;
{{/androidX}}
import dev.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
......
......@@ -8,9 +8,9 @@ import androidx.annotation.NonNull;
{{^androidX}}
import android.support.annotation.NonNull;
{{/androidX}}
import dev.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
......
......@@ -190,11 +190,11 @@ void main() {
await injectPlugins(flutterProject);
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');
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'));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
......@@ -282,7 +282,7 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()}
await injectPlugins(flutterProject);
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');
expect(registrant.readAsStringSync(),
......@@ -362,11 +362,11 @@ plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()}
await injectPlugins(flutterProject);
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');
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'));
}, overrides: <Type, Generator>{
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