[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:
@@ -192,6 +192,17 @@ class ApkExtractor {
|
||||
_extracted = true;
|
||||
}
|
||||
|
||||
/// Returns true if APK contains classes from library with given [libraryName].
|
||||
Future<bool> containsLibrary(String libraryName) async {
|
||||
await _extractDex();
|
||||
for (final String className in _classes) {
|
||||
if (className.startsWith(libraryName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Returns true if the APK contains a given class.
|
||||
Future<bool> containsClass(String className) async {
|
||||
await _extractDex();
|
||||
@@ -218,6 +229,14 @@ Future<String> getAndroidManifest(String apk) async {
|
||||
);
|
||||
}
|
||||
|
||||
/// Checks that the [apk] includes any classes from a particularly library with
|
||||
/// given [libraryName] in the [apk] and returns true if so, false otherwise.
|
||||
Future<bool> checkApkContainsMethodsFromLibrary(File apk, String libraryName) async {
|
||||
final ApkExtractor extractor = ApkExtractor(apk);
|
||||
final bool apkContainsMethodsFromLibrary = await extractor.containsLibrary(libraryName);
|
||||
return apkContainsMethodsFromLibrary;
|
||||
}
|
||||
|
||||
/// Checks that the classes are contained in the APK, throws otherwise.
|
||||
Future<void> checkApkContainsClasses(File apk, List<String> classes) async {
|
||||
final ApkExtractor extractor = ApkExtractor(apk);
|
||||
@@ -272,16 +291,17 @@ android {
|
||||
}
|
||||
|
||||
/// Adds a plugin to the pubspec.
|
||||
/// In pubspec, each dependency is expressed as key, value pair joined by a colon `:`.
|
||||
/// such as `plugin_a`:`^0.0.1` or `plugin_a`:`\npath: /some/path`.
|
||||
void addPlugin(String plugin, { String value = '' }) {
|
||||
final File pubspec = File(path.join(rootPath, 'pubspec.yaml'));
|
||||
String content = pubspec.readAsStringSync();
|
||||
content = content.replaceFirst(
|
||||
'${Platform.lineTerminator}dependencies:${Platform.lineTerminator}',
|
||||
'${Platform.lineTerminator}dependencies:${Platform.lineTerminator} $plugin: $value${Platform.lineTerminator}',
|
||||
);
|
||||
pubspec.writeAsStringSync(content, flush: true);
|
||||
///
|
||||
/// If a particular version of the [plugin] is desired, it should be included
|
||||
/// in the name as it would be in the `flutter pub add` command, e.g.
|
||||
/// `google_maps_flutter:^2.2.1`.
|
||||
///
|
||||
/// Include all other desired options for running `flutter pub add` to
|
||||
/// [options], e.g. `<String>['--path', 'path/to/plugin']`.
|
||||
Future<void> addPlugin(String plugin, {List<String> options = const <String>[]}) async {
|
||||
await inDirectory(Directory(rootPath), () async {
|
||||
await flutter('pub', options: <String>['add', plugin, ...options]);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> setMinSdkVersion(int sdkVersion) async {
|
||||
@@ -367,9 +387,9 @@ class FlutterPluginProject {
|
||||
final Directory parent;
|
||||
final String name;
|
||||
|
||||
static Future<FlutterPluginProject> create(Directory directory, String name) async {
|
||||
static Future<FlutterPluginProject> create(Directory directory, String name, {List<String> options = const <String>['--platforms=ios,android']}) async {
|
||||
await inDirectory(directory, () async {
|
||||
await flutter('create', options: <String>['--template=plugin', '--platforms=ios,android', name]);
|
||||
await flutter('create', options: <String>['--template=plugin', ...options, name]);
|
||||
});
|
||||
return FlutterPluginProject(directory, name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user