Add reason logging to v1 embedding warning message (#94636)
This commit is contained in:
parent
a607a60b4a
commit
dd6a11b7aa
@ -546,7 +546,8 @@ class AndroidProject extends FlutterProjectPlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void checkForDeprecation({DeprecationBehavior deprecationBehavior = DeprecationBehavior.none}) {
|
void checkForDeprecation({DeprecationBehavior deprecationBehavior = DeprecationBehavior.none}) {
|
||||||
if (getEmbeddingVersion() == AndroidEmbeddingVersion.v1) {
|
final AndroidEmbeddingVersionResult result = computeEmbeddingVersion();
|
||||||
|
if (result.version == AndroidEmbeddingVersion.v1) {
|
||||||
globals.printStatus(
|
globals.printStatus(
|
||||||
'''
|
'''
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
@ -562,6 +563,10 @@ to migrate your project. You may also pass the --ignore-deprecation flag to
|
|||||||
ignore this check and continue with the deprecated v1 embedding. However,
|
ignore this check and continue with the deprecated v1 embedding. However,
|
||||||
the v1 Android embedding will be removed in future versions of Flutter.
|
the v1 Android embedding will be removed in future versions of Flutter.
|
||||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
The detected reason was:
|
||||||
|
|
||||||
|
${result.reason}
|
||||||
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
'''
|
'''
|
||||||
);
|
);
|
||||||
switch (deprecationBehavior) {
|
switch (deprecationBehavior) {
|
||||||
@ -581,13 +586,17 @@ the v1 Android embedding will be removed in future versions of Flutter.
|
|||||||
}
|
}
|
||||||
|
|
||||||
AndroidEmbeddingVersion getEmbeddingVersion() {
|
AndroidEmbeddingVersion getEmbeddingVersion() {
|
||||||
|
return computeEmbeddingVersion().version;
|
||||||
|
}
|
||||||
|
|
||||||
|
AndroidEmbeddingVersionResult computeEmbeddingVersion() {
|
||||||
if (isModule) {
|
if (isModule) {
|
||||||
// A module type's Android project is used in add-to-app scenarios and
|
// A module type's Android project is used in add-to-app scenarios and
|
||||||
// only supports the V2 embedding.
|
// only supports the V2 embedding.
|
||||||
return AndroidEmbeddingVersion.v2;
|
return AndroidEmbeddingVersionResult(AndroidEmbeddingVersion.v2, 'Is add-to-app module');
|
||||||
}
|
}
|
||||||
if (appManifestFile == null || !appManifestFile.existsSync()) {
|
if (appManifestFile == null || !appManifestFile.existsSync()) {
|
||||||
return AndroidEmbeddingVersion.v1;
|
return AndroidEmbeddingVersionResult(AndroidEmbeddingVersion.v1, 'No `${appManifestFile.absolute.path}` file');
|
||||||
}
|
}
|
||||||
XmlDocument document;
|
XmlDocument document;
|
||||||
try {
|
try {
|
||||||
@ -602,7 +611,7 @@ the v1 Android embedding will be removed in future versions of Flutter.
|
|||||||
for (final XmlElement application in document.findAllElements('application')) {
|
for (final XmlElement application in document.findAllElements('application')) {
|
||||||
final String? applicationName = application.getAttribute('android:name');
|
final String? applicationName = application.getAttribute('android:name');
|
||||||
if (applicationName == 'io.flutter.app.FlutterApplication') {
|
if (applicationName == 'io.flutter.app.FlutterApplication') {
|
||||||
return AndroidEmbeddingVersion.v1;
|
return AndroidEmbeddingVersionResult(AndroidEmbeddingVersion.v1, '${appManifestFile.absolute.path} uses `android:name="io.flutter.app.FutterApplication"`');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final XmlElement metaData in document.findAllElements('meta-data')) {
|
for (final XmlElement metaData in document.findAllElements('meta-data')) {
|
||||||
@ -610,14 +619,14 @@ the v1 Android embedding will be removed in future versions of Flutter.
|
|||||||
if (name == 'flutterEmbedding') {
|
if (name == 'flutterEmbedding') {
|
||||||
final String? embeddingVersionString = metaData.getAttribute('android:value');
|
final String? embeddingVersionString = metaData.getAttribute('android:value');
|
||||||
if (embeddingVersionString == '1') {
|
if (embeddingVersionString == '1') {
|
||||||
return AndroidEmbeddingVersion.v1;
|
return AndroidEmbeddingVersionResult(AndroidEmbeddingVersion.v1, '${appManifestFile.absolute.path} `<meta-data android:name="flutterEmbedding"` has value 1');
|
||||||
}
|
}
|
||||||
if (embeddingVersionString == '2') {
|
if (embeddingVersionString == '2') {
|
||||||
return AndroidEmbeddingVersion.v2;
|
return AndroidEmbeddingVersionResult(AndroidEmbeddingVersion.v2, '${appManifestFile.absolute.path} `<meta-data android:name="flutterEmbedding"` has value 2');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return AndroidEmbeddingVersion.v1;
|
return AndroidEmbeddingVersionResult(AndroidEmbeddingVersion.v1, 'No `<meta-data android:name="flutterEmbedding" android:value="2"/>` in ${appManifestFile.absolute.path}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,6 +638,19 @@ enum AndroidEmbeddingVersion {
|
|||||||
v2,
|
v2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Data class that holds the results of checking for embedding version.
|
||||||
|
///
|
||||||
|
/// This class includes the reason why a particular embedding was selected.
|
||||||
|
class AndroidEmbeddingVersionResult {
|
||||||
|
AndroidEmbeddingVersionResult(this.version, this.reason);
|
||||||
|
|
||||||
|
/// The embedding version.
|
||||||
|
AndroidEmbeddingVersion version;
|
||||||
|
|
||||||
|
/// The reason why the embedding version was selected.
|
||||||
|
String reason;
|
||||||
|
}
|
||||||
|
|
||||||
// What the tool should do when encountering deprecated API in applications.
|
// What the tool should do when encountering deprecated API in applications.
|
||||||
enum DeprecationBehavior {
|
enum DeprecationBehavior {
|
||||||
// The command being run does not care about deprecation status.
|
// The command being run does not care about deprecation status.
|
||||||
|
@ -1632,6 +1632,11 @@ class FakeAndroidProject extends Fake implements AndroidProject {
|
|||||||
AndroidEmbeddingVersion getEmbeddingVersion() {
|
AndroidEmbeddingVersion getEmbeddingVersion() {
|
||||||
return embeddingVersion;
|
return embeddingVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
AndroidEmbeddingVersionResult computeEmbeddingVersion() {
|
||||||
|
return AndroidEmbeddingVersionResult(embeddingVersion, 'reasons for version');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakeWebProject extends Fake implements WebProject {
|
class FakeWebProject extends Fake implements WebProject {
|
||||||
|
@ -196,6 +196,7 @@ void main() {
|
|||||||
contains('Build failed due to use of deprecated Android v1 embedding.')
|
contains('Build failed due to use of deprecated Android v1 embedding.')
|
||||||
);
|
);
|
||||||
expect(testLogger.statusText, contains('https://flutter.dev/go/android-project-migration'));
|
expect(testLogger.statusText, contains('https://flutter.dev/go/android-project-migration'));
|
||||||
|
expect(testLogger.statusText, contains('No `<meta-data android:name="flutterEmbedding" android:value="2"/>` in '));
|
||||||
});
|
});
|
||||||
_testInMemory('Android project not on v2 embedding ignore continues', () async {
|
_testInMemory('Android project not on v2 embedding ignore continues', () async {
|
||||||
final FlutterProject project = await someProject();
|
final FlutterProject project = await someProject();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user