This commit is contained in:
@@ -36,6 +36,7 @@ class BuildApkCommand extends BuildSubCommand {
|
||||
usesAnalyzeSizeFlag();
|
||||
addAndroidSpecificBuildOptions(hide: !verboseHelp);
|
||||
addMultidexOption();
|
||||
addIgnoreDeprecationOption();
|
||||
argParser
|
||||
..addFlag('split-per-abi',
|
||||
negatable: false,
|
||||
@@ -54,6 +55,9 @@ class BuildApkCommand extends BuildSubCommand {
|
||||
@override
|
||||
final String name = 'apk';
|
||||
|
||||
@override
|
||||
DeprecationBehavior get deprecationBehavior => boolArg('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit;
|
||||
|
||||
@override
|
||||
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
|
||||
DevelopmentArtifact.androidGenSnapshot,
|
||||
|
||||
@@ -42,6 +42,7 @@ class BuildAppBundleCommand extends BuildSubCommand {
|
||||
usesAnalyzeSizeFlag();
|
||||
addAndroidSpecificBuildOptions(hide: !verboseHelp);
|
||||
addMultidexOption();
|
||||
addIgnoreDeprecationOption();
|
||||
argParser.addMultiOption('target-platform',
|
||||
splitCommas: true,
|
||||
defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'],
|
||||
@@ -72,6 +73,9 @@ class BuildAppBundleCommand extends BuildSubCommand {
|
||||
@override
|
||||
final String name = 'appbundle';
|
||||
|
||||
@override
|
||||
DeprecationBehavior get deprecationBehavior => boolArg('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit;
|
||||
|
||||
@override
|
||||
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
|
||||
DevelopmentArtifact.androidGenSnapshot,
|
||||
|
||||
@@ -251,6 +251,7 @@ class RunCommand extends RunCommandBase {
|
||||
// without needing to know the port.
|
||||
addPublishPort(verboseHelp: verboseHelp);
|
||||
addMultidexOption();
|
||||
addIgnoreDeprecationOption();
|
||||
argParser
|
||||
..addFlag('enable-software-rendering',
|
||||
negatable: false,
|
||||
@@ -342,6 +343,10 @@ class RunCommand extends RunCommandBase {
|
||||
@override
|
||||
final String name = 'run';
|
||||
|
||||
@override
|
||||
DeprecationBehavior get deprecationBehavior => boolArg('ignore-deprecation') ? DeprecationBehavior.ignore : _deviceDeprecationBehavior;
|
||||
DeprecationBehavior _deviceDeprecationBehavior = DeprecationBehavior.none;
|
||||
|
||||
@override
|
||||
final String description = 'Run your Flutter app on an attached device.';
|
||||
|
||||
@@ -475,6 +480,10 @@ class RunCommand extends RunCommandBase {
|
||||
'--${FlutterOptions.kDeviceUser} is only supported for Android. At least one Android device is required.'
|
||||
);
|
||||
}
|
||||
|
||||
if (devices.any((Device device) => device is AndroidDevice)) {
|
||||
_deviceDeprecationBehavior = DeprecationBehavior.exit;
|
||||
}
|
||||
// Only support "web mode" with a single web device due to resident runner
|
||||
// refactoring required otherwise.
|
||||
webMode = featureFlags.isWebEnabled &&
|
||||
|
||||
@@ -20,6 +20,7 @@ import 'flutter_manifest.dart';
|
||||
import 'flutter_plugins.dart';
|
||||
import 'globals.dart' as globals;
|
||||
import 'platform_plugins.dart';
|
||||
import 'reporting/reporting.dart';
|
||||
import 'template.dart';
|
||||
import 'xcode_project.dart';
|
||||
|
||||
@@ -282,7 +283,7 @@ class FlutterProject {
|
||||
/// registrants for app and module projects only.
|
||||
///
|
||||
/// Will not create project platform directories if they do not already exist.
|
||||
Future<void> regeneratePlatformSpecificTooling() async {
|
||||
Future<void> regeneratePlatformSpecificTooling({DeprecationBehavior deprecationBehavior = DeprecationBehavior.none}) async {
|
||||
return ensureReadyForPlatformSpecificTooling(
|
||||
androidPlatform: android.existsSync(),
|
||||
iosPlatform: ios.existsSync(),
|
||||
@@ -293,6 +294,7 @@ class FlutterProject {
|
||||
windowsPlatform: featureFlags.isWindowsEnabled && windows.existsSync(),
|
||||
webPlatform: featureFlags.isWebEnabled && web.existsSync(),
|
||||
winUwpPlatform: featureFlags.isWindowsUwpEnabled && windowsUwp.existsSync(),
|
||||
deprecationBehavior: deprecationBehavior,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -306,13 +308,14 @@ class FlutterProject {
|
||||
bool windowsPlatform = false,
|
||||
bool webPlatform = false,
|
||||
bool winUwpPlatform = false,
|
||||
DeprecationBehavior deprecationBehavior = DeprecationBehavior.none,
|
||||
}) async {
|
||||
if (!directory.existsSync() || hasExampleApp || isPlugin) {
|
||||
return;
|
||||
}
|
||||
await refreshPluginsList(this, iosPlatform: iosPlatform, macOSPlatform: macOSPlatform);
|
||||
if (androidPlatform) {
|
||||
await android.ensureReadyForPlatformSpecificTooling();
|
||||
await android.ensureReadyForPlatformSpecificTooling(deprecationBehavior: deprecationBehavior);
|
||||
}
|
||||
if (iosPlatform) {
|
||||
await ios.ensureReadyForPlatformSpecificTooling();
|
||||
@@ -344,6 +347,12 @@ class FlutterProject {
|
||||
);
|
||||
}
|
||||
|
||||
void checkForDeprecation({DeprecationBehavior deprecationBehavior = DeprecationBehavior.none}) {
|
||||
if (android.existsSync()) {
|
||||
android.checkForDeprecation(deprecationBehavior: deprecationBehavior);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a json encoded string containing the [appName], [version], and [buildNumber] that is used to generate version.json
|
||||
String getVersionInfo() {
|
||||
final String? buildName = manifest.buildName;
|
||||
@@ -478,7 +487,7 @@ class AndroidProject extends FlutterProjectPlatform {
|
||||
return parent.directory.childDirectory('build');
|
||||
}
|
||||
|
||||
Future<void> ensureReadyForPlatformSpecificTooling() async {
|
||||
Future<void> ensureReadyForPlatformSpecificTooling({DeprecationBehavior deprecationBehavior = DeprecationBehavior.none}) async {
|
||||
if (isModule && _shouldRegenerateFromTemplate()) {
|
||||
await _regenerateLibrary();
|
||||
// Add ephemeral host app, if an editable host app does not already exist.
|
||||
@@ -536,6 +545,41 @@ class AndroidProject extends FlutterProjectPlatform {
|
||||
);
|
||||
}
|
||||
|
||||
void checkForDeprecation({DeprecationBehavior deprecationBehavior = DeprecationBehavior.none}) {
|
||||
if (getEmbeddingVersion() == AndroidEmbeddingVersion.v1) {
|
||||
globals.printStatus(
|
||||
'''
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Warning
|
||||
──────────────────────────────────────────────────────────────────────────────
|
||||
Your Flutter application is created using an older version of the Android
|
||||
embedding. It is being deprecated in favor of Android embedding v2. Follow the
|
||||
steps at
|
||||
|
||||
https://flutter.dev/go/android-project-migration
|
||||
|
||||
to migrate your project. You may also pass the --ignore-deprecation flag to
|
||||
ignore this check and continue with the deprecated v1 embedding. However,
|
||||
the v1 Android embedding will be removed in future versions of Flutter.
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
'''
|
||||
);
|
||||
switch (deprecationBehavior) {
|
||||
case DeprecationBehavior.none:
|
||||
break;
|
||||
case DeprecationBehavior.ignore:
|
||||
BuildEvent('deprecated-v1-android-embedding-ignored', type: 'gradle', flutterUsage: globals.flutterUsage).send();
|
||||
break;
|
||||
case DeprecationBehavior.exit:
|
||||
BuildEvent('deprecated-v1-android-embedding-failed', type: 'gradle', flutterUsage: globals.flutterUsage).send();
|
||||
throwToolExit(
|
||||
'Build failed due to use of deprecated Android v1 embedding.',
|
||||
exitCode: 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AndroidEmbeddingVersion getEmbeddingVersion() {
|
||||
if (isModule) {
|
||||
// A module type's Android project is used in add-to-app scenarios and
|
||||
@@ -555,6 +599,12 @@ class AndroidProject extends FlutterProjectPlatform {
|
||||
throwToolExit('Error reading $appManifestFile even though it exists. '
|
||||
'Please ensure that you have read permission to this file and try again.');
|
||||
}
|
||||
for (final XmlElement application in document.findAllElements('application')) {
|
||||
final String? applicationName = application.getAttribute('android:name');
|
||||
if (applicationName == 'io.flutter.app.FlutterApplication') {
|
||||
return AndroidEmbeddingVersion.v1;
|
||||
}
|
||||
}
|
||||
for (final XmlElement metaData in document.findAllElements('meta-data')) {
|
||||
final String? name = metaData.getAttribute('android:name');
|
||||
if (name == 'flutterEmbedding') {
|
||||
@@ -579,6 +629,16 @@ enum AndroidEmbeddingVersion {
|
||||
v2,
|
||||
}
|
||||
|
||||
// What the tool should do when encountering deprecated API in applications.
|
||||
enum DeprecationBehavior {
|
||||
// The command being run does not care about deprecation status.
|
||||
none,
|
||||
// The command should continue and ignore the deprecation warning.
|
||||
ignore,
|
||||
// The command should exit the tool.
|
||||
exit,
|
||||
}
|
||||
|
||||
/// Represents the web sub-project of a Flutter project.
|
||||
class WebProject extends FlutterProjectPlatform {
|
||||
WebProject._(this.parent);
|
||||
|
||||
@@ -181,6 +181,8 @@ abstract class FlutterCommand extends Command<void> {
|
||||
|
||||
bool _usesFatalWarnings = false;
|
||||
|
||||
DeprecationBehavior get deprecationBehavior => DeprecationBehavior.none;
|
||||
|
||||
bool get shouldRunPub => _usesPubOption && boolArg('pub');
|
||||
|
||||
bool get shouldUpdateCache => true;
|
||||
@@ -834,6 +836,15 @@ abstract class FlutterCommand extends Command<void> {
|
||||
);
|
||||
}
|
||||
|
||||
void addIgnoreDeprecationOption({ bool hide = false }) {
|
||||
argParser.addFlag('ignore-deprecation',
|
||||
negatable: false,
|
||||
help: 'Indicates that the app should ignore deprecation warnings and continue to build '
|
||||
'using deprecated APIs. Use of this flag may cause your app to fail to build when '
|
||||
'deprecated APIs are removed.',
|
||||
);
|
||||
}
|
||||
|
||||
/// Adds build options common to all of the desktop build commands.
|
||||
void addCommonDesktopBuildOptions({ required bool verboseHelp }) {
|
||||
addBuildModeFlags(verboseHelp: verboseHelp);
|
||||
@@ -1263,8 +1274,10 @@ abstract class FlutterCommand extends Command<void> {
|
||||
|
||||
await validateCommand();
|
||||
|
||||
final FlutterProject project = FlutterProject.current();
|
||||
project.checkForDeprecation(deprecationBehavior: deprecationBehavior);
|
||||
|
||||
if (shouldRunPub) {
|
||||
final FlutterProject project = FlutterProject.current();
|
||||
final Environment environment = Environment(
|
||||
artifacts: globals.artifacts!,
|
||||
logger: globals.logger,
|
||||
|
||||
Reference in New Issue
Block a user