Prevent building non-android plugins in build aar (#58018)
This commit is contained in:
parent
8432204194
commit
4465ff9e3d
@ -24,11 +24,11 @@ Future<void> main() async {
|
|||||||
return TaskResult.failure('Could not find Java');
|
return TaskResult.failure('Could not find Java');
|
||||||
print('\nUsing JAVA_HOME=$javaHome');
|
print('\nUsing JAVA_HOME=$javaHome');
|
||||||
|
|
||||||
section('Create module project');
|
|
||||||
|
|
||||||
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_module_test.');
|
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_module_test.');
|
||||||
final Directory projectDir = Directory(path.join(tempDir.path, 'hello'));
|
final Directory projectDir = Directory(path.join(tempDir.path, 'hello'));
|
||||||
try {
|
try {
|
||||||
|
section('Create module project');
|
||||||
|
|
||||||
await inDirectory(tempDir, () async {
|
await inDirectory(tempDir, () async {
|
||||||
await flutter(
|
await flutter(
|
||||||
'create',
|
'create',
|
||||||
@ -36,15 +36,55 @@ Future<void> main() async {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
section('Add plugins');
|
section('Create plugin that supports android platform');
|
||||||
|
|
||||||
final File pubspec = File(path.join(projectDir.path, 'pubspec.yaml'));
|
await inDirectory(tempDir, () async {
|
||||||
String content = pubspec.readAsStringSync();
|
await flutter(
|
||||||
|
'create',
|
||||||
|
options: <String>['--org', 'io.flutter.devicelab', '--template', 'plugin', 'plugin_with_android'],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
section('Create plugin that doesn\'t support android project');
|
||||||
|
|
||||||
|
await inDirectory(tempDir, () async {
|
||||||
|
await flutter(
|
||||||
|
'create',
|
||||||
|
options: <String>['--org', 'io.flutter.devicelab', '--template', 'plugin', 'plugin_without_android'],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete the android/ directory.
|
||||||
|
File(path.join(
|
||||||
|
tempDir.path,
|
||||||
|
'plugin_without_android',
|
||||||
|
'android'
|
||||||
|
)).deleteSync(recursive: true);
|
||||||
|
|
||||||
|
// Remove Android support from the plugin pubspec.yaml
|
||||||
|
final File pluginPubspec = File(path.join(tempDir.path, 'plugin_without_android', 'pubspec.yaml'));
|
||||||
|
pluginPubspec.writeAsStringSync(pluginPubspec.readAsStringSync().replaceFirst('''
|
||||||
|
android:
|
||||||
|
package: io.flutter.devicelab.plugin_without_android
|
||||||
|
pluginClass: PluginWithoutAndroidPlugin
|
||||||
|
''', ''), flush: true);
|
||||||
|
|
||||||
|
section('Add plugins to pubspec.yaml');
|
||||||
|
|
||||||
|
final File modulePubspec = File(path.join(projectDir.path, 'pubspec.yaml'));
|
||||||
|
String content = modulePubspec.readAsStringSync();
|
||||||
content = content.replaceFirst(
|
content = content.replaceFirst(
|
||||||
'\ndependencies:\n',
|
'\ndependencies:\n',
|
||||||
'\ndependencies:\n device_info: 0.4.1\n package_info: 0.4.0+9\n',
|
'\ndependencies:\n'
|
||||||
|
' plugin_with_android:\n'
|
||||||
|
' path: ../plugin_with_android\n'
|
||||||
|
' plugin_without_android:\n'
|
||||||
|
' path: ../plugin_without_android\n',
|
||||||
);
|
);
|
||||||
pubspec.writeAsStringSync(content, flush: true);
|
modulePubspec.writeAsStringSync(content, flush: true);
|
||||||
|
|
||||||
|
section('Run packages get in module project');
|
||||||
|
|
||||||
await inDirectory(projectDir, () async {
|
await inDirectory(projectDir, () async {
|
||||||
await flutter(
|
await flutter(
|
||||||
'packages',
|
'packages',
|
||||||
@ -57,7 +97,7 @@ Future<void> main() async {
|
|||||||
await inDirectory(projectDir, () async {
|
await inDirectory(projectDir, () async {
|
||||||
await flutter(
|
await flutter(
|
||||||
'build',
|
'build',
|
||||||
options: <String>['aar', '--release', '--verbose'],
|
options: <String>['aar', '--verbose'],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -99,44 +139,22 @@ Future<void> main() async {
|
|||||||
repoPath,
|
repoPath,
|
||||||
'io',
|
'io',
|
||||||
'flutter',
|
'flutter',
|
||||||
'plugins',
|
'devicelab',
|
||||||
'deviceinfo',
|
'plugin_with_android',
|
||||||
'device_info_release',
|
'plugin_with_android_release',
|
||||||
'1.0',
|
'1.0',
|
||||||
'device_info_release-1.0.aar',
|
'plugin_with_android_release-1.0.aar',
|
||||||
));
|
));
|
||||||
|
|
||||||
checkFileExists(path.join(
|
checkFileExists(path.join(
|
||||||
repoPath,
|
repoPath,
|
||||||
'io',
|
'io',
|
||||||
'flutter',
|
'flutter',
|
||||||
'plugins',
|
'devicelab',
|
||||||
'deviceinfo',
|
'plugin_with_android',
|
||||||
'device_info_release',
|
'plugin_with_android_release',
|
||||||
'1.0',
|
'1.0',
|
||||||
'device_info_release-1.0.pom',
|
'plugin_with_android_release-1.0.pom',
|
||||||
));
|
|
||||||
|
|
||||||
checkFileExists(path.join(
|
|
||||||
repoPath,
|
|
||||||
'io',
|
|
||||||
'flutter',
|
|
||||||
'plugins',
|
|
||||||
'packageinfo',
|
|
||||||
'package_info_release',
|
|
||||||
'1.0',
|
|
||||||
'package_info_release-1.0.aar',
|
|
||||||
));
|
|
||||||
|
|
||||||
checkFileExists(path.join(
|
|
||||||
repoPath,
|
|
||||||
'io',
|
|
||||||
'flutter',
|
|
||||||
'plugins',
|
|
||||||
'packageinfo',
|
|
||||||
'package_info_release',
|
|
||||||
'1.0',
|
|
||||||
'package_info_release-1.0.pom',
|
|
||||||
));
|
));
|
||||||
|
|
||||||
section('Check AOT blobs in release POM');
|
section('Check AOT blobs in release POM');
|
||||||
@ -146,8 +164,7 @@ Future<void> main() async {
|
|||||||
'armeabi_v7a_release',
|
'armeabi_v7a_release',
|
||||||
'arm64_v8a_release',
|
'arm64_v8a_release',
|
||||||
'x86_64_release',
|
'x86_64_release',
|
||||||
'package_info_release',
|
'plugin_with_android_release',
|
||||||
'device_info_release',
|
|
||||||
], releasePom);
|
], releasePom);
|
||||||
|
|
||||||
section('Check assets in release AAR');
|
section('Check assets in release AAR');
|
||||||
@ -174,15 +191,6 @@ Future<void> main() async {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
section('Build debug AAR');
|
|
||||||
|
|
||||||
await inDirectory(projectDir, () async {
|
|
||||||
await flutter(
|
|
||||||
'build',
|
|
||||||
options: <String>['aar', '--verbose', '--debug'],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
section('Check debug Maven artifacts');
|
section('Check debug Maven artifacts');
|
||||||
|
|
||||||
checkFileExists(path.join(
|
checkFileExists(path.join(
|
||||||
@ -213,44 +221,22 @@ Future<void> main() async {
|
|||||||
repoPath,
|
repoPath,
|
||||||
'io',
|
'io',
|
||||||
'flutter',
|
'flutter',
|
||||||
'plugins',
|
'devicelab',
|
||||||
'deviceinfo',
|
'plugin_with_android',
|
||||||
'device_info_debug',
|
'plugin_with_android_debug',
|
||||||
'1.0',
|
'1.0',
|
||||||
'device_info_debug-1.0.aar',
|
'plugin_with_android_debug-1.0.aar',
|
||||||
));
|
));
|
||||||
|
|
||||||
checkFileExists(path.join(
|
checkFileExists(path.join(
|
||||||
repoPath,
|
repoPath,
|
||||||
'io',
|
'io',
|
||||||
'flutter',
|
'flutter',
|
||||||
'plugins',
|
'devicelab',
|
||||||
'deviceinfo',
|
'plugin_with_android',
|
||||||
'device_info_debug',
|
'plugin_with_android_debug',
|
||||||
'1.0',
|
'1.0',
|
||||||
'device_info_debug-1.0.pom',
|
'plugin_with_android_debug-1.0.pom',
|
||||||
));
|
|
||||||
|
|
||||||
checkFileExists(path.join(
|
|
||||||
repoPath,
|
|
||||||
'io',
|
|
||||||
'flutter',
|
|
||||||
'plugins',
|
|
||||||
'packageinfo',
|
|
||||||
'package_info_debug',
|
|
||||||
'1.0',
|
|
||||||
'package_info_debug-1.0.aar',
|
|
||||||
));
|
|
||||||
|
|
||||||
checkFileExists(path.join(
|
|
||||||
repoPath,
|
|
||||||
'io',
|
|
||||||
'flutter',
|
|
||||||
'plugins',
|
|
||||||
'packageinfo',
|
|
||||||
'package_info_debug',
|
|
||||||
'1.0',
|
|
||||||
'package_info_debug-1.0.pom',
|
|
||||||
));
|
));
|
||||||
|
|
||||||
section('Check AOT blobs in debug POM');
|
section('Check AOT blobs in debug POM');
|
||||||
@ -261,8 +247,7 @@ Future<void> main() async {
|
|||||||
'x86_64_debug',
|
'x86_64_debug',
|
||||||
'armeabi_v7a_debug',
|
'armeabi_v7a_debug',
|
||||||
'arm64_v8a_debug',
|
'arm64_v8a_debug',
|
||||||
'package_info_debug',
|
'plugin_with_android_debug',
|
||||||
'device_info_debug',
|
|
||||||
], debugPom);
|
], debugPom);
|
||||||
|
|
||||||
section('Check assets in debug AAR');
|
section('Check assets in debug AAR');
|
||||||
|
@ -73,6 +73,14 @@ void configureProject(Project project, String outputDir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void configurePlugin(Project project, String outputDir) {
|
||||||
|
if (!project.hasProperty("android")) {
|
||||||
|
// A plugin doesn't support the Android platform when this property isn't defined in the plugin.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
configureProject(project, outputDir)
|
||||||
|
}
|
||||||
|
|
||||||
String getFlutterRoot(Project project) {
|
String getFlutterRoot(Project project) {
|
||||||
if (!project.hasProperty("flutter-root")) {
|
if (!project.hasProperty("flutter-root")) {
|
||||||
throw new GradleException("The `-Pflutter-root` flag must be specified.")
|
throw new GradleException("The `-Pflutter-root` flag must be specified.")
|
||||||
@ -158,7 +166,7 @@ projectsEvaluated {
|
|||||||
// This is due to the Android Gradle Plugin expecting all library subprojects to be published
|
// This is due to the Android Gradle Plugin expecting all library subprojects to be published
|
||||||
// as Maven artifacts.
|
// as Maven artifacts.
|
||||||
modulePlugins.each { pluginProject ->
|
modulePlugins.each { pluginProject ->
|
||||||
configureProject(pluginProject, moduleProject.property("output-dir"))
|
configurePlugin(pluginProject, moduleProject.property("output-dir"))
|
||||||
moduleProject.android.libraryVariants.all { variant ->
|
moduleProject.android.libraryVariants.all { variant ->
|
||||||
// Configure the `assembleAar<variantName>` task for each plugin's projects and make
|
// Configure the `assembleAar<variantName>` task for each plugin's projects and make
|
||||||
// the module's equivalent task depend on the plugin's task.
|
// the module's equivalent task depend on the plugin's task.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user