[Android] Removes dev dependency plugins from release builds (#158026)

Removes plugins that are `dev_dependency`s from being dependencies of
release builds of Flutter Android app projects.

Fixes https://github.com/flutter/flutter/issues/157949.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.


<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
Camille Simon
2024-12-04 13:13:07 -05:00
committed by GitHub
parent e1e4ee9a01
commit f9f42bee99
8 changed files with 171 additions and 31 deletions

View File

@@ -0,0 +1,60 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:flutter_devicelab/framework/apk_utils.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/task_result.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;
Future<void> main() async {
await task(() async {
try {
await runProjectTest((FlutterProject flutterProject) async {
// Create dev_dependency plugin to use for test.
final Directory tempDir = Directory.systemTemp.createTempSync('android_release_builds_exclude_dev_dependencies_test.');
const String devDependencyPluginOrg = 'com.example.dev_dependency_plugin';
await FlutterPluginProject.create(tempDir, 'dev_dependency_plugin', options: <String>['--platforms=android', '--org=$devDependencyPluginOrg']);
// Add devDependencyPlugin as dependency of flutterProject.
await flutterProject.addPlugin('dev_dependency_plugin', options: <String>['--path', path.join(tempDir.path, 'dev_dependency_plugin')]);
final List<String> buildModesToTest = <String>['debug', 'profile', 'release'];
for (final String buildMode in buildModesToTest) {
section('APK does contain methods from dev dependency in $buildMode mode');
// Build APK in buildMode and check that devDependencyPlugin is included/excluded in the APK as expected.
await inDirectory(flutterProject.rootPath, () async {
await flutter('build', options: <String>[
'apk',
'--$buildMode',
'--target-platform=android-arm',
]);
final File apk = File(path.join(flutterProject.rootPath, 'build', 'app', 'outputs', 'flutter-apk', 'app-debug.apk'));
if (!apk.existsSync()) {
throw TaskResult.failure("Expected ${apk.path} to exist, but it doesn't.");
}
// We expect the APK to include the devDependencyPlugin except in release mode.
final bool isTestingReleaseMode = buildMode == 'release';
final bool apkIncludesDevDependency = await checkApkContainsMethodsFromLibrary(apk, devDependencyPluginOrg);
final bool apkIncludesDevDependencyAsExpected = isTestingReleaseMode ? !apkIncludesDevDependency : apkIncludesDevDependency;
if (!apkIncludesDevDependencyAsExpected) {
return TaskResult.failure('Expected to${isTestingReleaseMode ? ' not' : ''} find dev_dependency_plugin in APK built with debug mode but did${isTestingReleaseMode ? '' : ' not'}.');
}
});
}
});
return TaskResult.success(null);
} on TaskResult catch (taskResult) {
return taskResult;
} catch (e) {
return TaskResult.failure(e.toString());
}
});
}

View File

@@ -16,7 +16,7 @@ Future<void> main() async {
await runProjectTest((FlutterProject flutterProject) async {
section('APK contains plugin classes');
await flutterProject.setMinSdkVersion(20);
flutterProject.addPlugin('google_maps_flutter', value: '^2.2.1');
await flutterProject.addPlugin('google_maps_flutter:^2.2.1');
await inDirectory(flutterProject.rootPath, () async {
await flutter('build', options: <String>[

View File

@@ -210,8 +210,7 @@ Future<void> main() async {
});
section('Configure');
project.addPlugin('plugin_under_test',
value: '${Platform.lineTerminator} path: ${pluginDir.path}');
await project.addPlugin('plugin_under_test', options: <String>['--path', pluginDir.path]);
await project.addCustomBuildType('local', initWith: 'debug');
await project.getPackages();
@@ -229,7 +228,7 @@ Future<void> main() async {
section('gradlew assembleLocal (plugin with custom build type)');
await project.addCustomBuildType('local', initWith: 'debug');
section('Add plugin');
project.addPlugin('path_provider');
await project.addPlugin('path_provider');
await project.getPackages();
await project.runGradleTask('assembleLocal');