[CP-beta]Add deprecation notice for Android x86 when building for the target (#159847)
This pull request is created by [automatic cherry pick
workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate
this cherry pick request.
### Issue Link:
What is the link to the issue this cherry-pick is addressing?
https://github.com/flutter/flutter/issues/157543
### Changelog Description:
Explain this cherry pick in one line that is accessible to most Flutter
developers. See [best
practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md)
for examples
Add deprecation notice for Android x86 support, which will be removed in
next stable release after 3.27.
### Impact Description:
What is the impact (ex. visual jank on Samsung phones, app crash, cannot
ship an iOS app)? Does it impact development (ex. flutter doctor crashes
when Android Studio is installed), or the shipping production app (the
app crashes on launch)
A deprecation notice will be printed when users build or run an x86
Android application.
### Workaround:
Is there a workaround for this issue?
No, this is simply a deprecation notice.
### Risk:
What is the risk level of this cherry-pick?
- [X] Low
- [ ] Medium
- [ ] High
### Test Coverage:
Are you confident that your fix is well-tested by automated tests?
- [X] Yes
- [ ] No
### Validation Steps:
What are the steps to validate that this fix works?
Run `flutter build apk --target-platform=android-x86` and observe a
deprecation notice is printed.
Co-authored-by: Ben Konyi <bkonyi@google.com>
diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart
index eb647f2..9542fb3 100644
--- a/packages/flutter_tools/lib/src/android/gradle.dart
+++ b/packages/flutter_tools/lib/src/android/gradle.dart
@@ -122,6 +122,11 @@
return _taskFor('assembleAar', buildInfo);
}
+@visibleForTesting
+const String androidX86DeprecationWarning =
+ 'Support for Android x86 targets will be removed in the next stable release after 3.27. '
+ 'See https://github.com/flutter/flutter/issues/157543 for details.';
+
/// Returns the output APK file names for a given [AndroidBuildInfo].
///
/// For example, when [splitPerAbi] is true, multiple APKs are created.
@@ -188,6 +193,13 @@
// Module projects artifacts are located in `build/host`.
outputDirectory = outputDirectory.childDirectory('host');
}
+
+ final bool containsX86Targets = androidBuildInfo.where(
+ (AndroidBuildInfo info) => info.containsX86Target,
+ ).isNotEmpty;
+ if (containsX86Targets) {
+ _logger.printWarning(androidX86DeprecationWarning);
+ }
for (final AndroidBuildInfo androidBuildInfo in androidBuildInfo) {
await buildGradleAar(
project: project,
@@ -300,6 +312,9 @@
int retry = 0,
@visibleForTesting int? maxRetries,
}) async {
+ if (androidBuildInfo.containsX86Target) {
+ _logger.printWarning(androidX86DeprecationWarning);
+ }
if (!project.android.isSupportedVersion) {
_exitWithUnsupportedProjectMessage(_logger.terminal, _analytics);
}
diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart
index a9477c7..0d1ec5b 100644
--- a/packages/flutter_tools/lib/src/build_info.dart
+++ b/packages/flutter_tools/lib/src/build_info.dart
@@ -396,6 +396,8 @@
/// The target platforms for the build.
final Iterable<AndroidArch> targetArchs;
+ bool get containsX86Target => targetArchs.contains(AndroidArch.x86);
+
/// Whether to bootstrap an empty application.
final bool fastStart;
}
diff --git a/packages/flutter_tools/test/general.shard/android/android_gradle_builder_test.dart b/packages/flutter_tools/test/general.shard/android/android_gradle_builder_test.dart
index 36f40a7..a80a0e3 100644
--- a/packages/flutter_tools/test/general.shard/android/android_gradle_builder_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/android_gradle_builder_test.dart
@@ -811,6 +811,85 @@
AndroidStudio: () => FakeAndroidStudio(),
});
+ testUsingContext('prints deprecation warning when building for x86', () async {
+ // See https://github.com/flutter/flutter/issues/157543 for details.
+ final AndroidGradleBuilder builder = AndroidGradleBuilder(
+ java: FakeJava(),
+ logger: logger,
+ processManager: processManager,
+ fileSystem: fileSystem,
+ artifacts: Artifacts.test(),
+ analytics: fakeAnalytics,
+ gradleUtils: FakeGradleUtils(),
+ platform: FakePlatform(),
+ androidStudio: FakeAndroidStudio(),
+ );
+ processManager.addCommand(const FakeCommand(
+ command: <String>[
+ 'gradlew',
+ '-q',
+ '-Ptarget-platform=android-x86',
+ '-Ptarget=lib/main.dart',
+ '-Pbase-application-name=android.app.Application',
+ '-Pdart-obfuscation=false',
+ '-Ptrack-widget-creation=false',
+ '-Ptree-shake-icons=false',
+ 'assembleRelease',
+ ],
+ ));
+ fileSystem.directory('android')
+ .childFile('build.gradle')
+ .createSync(recursive: true);
+
+ fileSystem.directory('android')
+ .childFile('gradle.properties')
+ .createSync(recursive: true);
+
+ fileSystem.directory('android')
+ .childDirectory('app')
+ .childFile('build.gradle')
+ ..createSync(recursive: true)
+ ..writeAsStringSync('apply from: irrelevant/flutter.gradle');
+
+ fileSystem.directory('build')
+ .childDirectory('app')
+ .childDirectory('outputs')
+ .childDirectory('flutter-apk')
+ .childFile('app-release.apk')
+ .createSync(recursive: true);
+
+ final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
+ project.android.appManifestFile
+ ..createSync(recursive: true)
+ ..writeAsStringSync(minimalV2EmbeddingManifest);
+
+ await builder.buildGradleApp(
+ project: project,
+ androidBuildInfo: const AndroidBuildInfo(
+ BuildInfo(
+ BuildMode.release,
+ null,
+ treeShakeIcons: false,
+ packageConfigPath: '.dart_tool/package_config.json',
+ ),
+ targetArchs: <AndroidArch>[AndroidArch.x86],
+ ),
+ target: 'lib/main.dart',
+ isBuildingBundle: false,
+ configOnly: false,
+ localGradleErrors: const <GradleHandledError>[],
+ );
+
+ expect(
+ logger.statusText,
+ contains('Built build/app/outputs/flutter-apk/app-release.apk (0.0MB)'),
+ );
+ expect(logger.warningText, contains(androidX86DeprecationWarning));
+ expect(processManager, hasNoRemainingExpectations);
+ }, overrides: <Type, Generator>{
+ AndroidStudio: () => FakeAndroidStudio(),
+ });
+
testUsingContext('Uses namespace attribute if manifest lacks a package attribute', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final AndroidSdk sdk = FakeAndroidSdk();