diff --git a/packages/flutter_tools/lib/src/android/gradle_errors.dart b/packages/flutter_tools/lib/src/android/gradle_errors.dart index 3e682f2d22..bfbb984ea1 100644 --- a/packages/flutter_tools/lib/src/android/gradle_errors.dart +++ b/packages/flutter_tools/lib/src/android/gradle_errors.dart @@ -78,6 +78,7 @@ final List gradleErrors = [ remoteTerminatedHandshakeHandler, couldNotOpenCacheDirectoryHandler, incompatibleCompileSdk35AndAgpVersionHandler, + usageOfV1EmbeddingReferencesHandler, jlinkErrorWithJava21AndSourceCompatibility, incompatibleKotlinVersionHandler, // This handler should always be last, as its key log output is sometimes in error messages with other root causes. ]; @@ -681,6 +682,31 @@ ${_getAgpLocation(project)}''', title: _boxTitle); eventLabel: 'r8-dexing-bug-in-AGP-7.3', ); +// Handler for when an outdated plugin is still using v1 embedding references that +// were possibly removed in more recent plugin versions. +@visibleForTesting +final GradleHandledError usageOfV1EmbeddingReferencesHandler = GradleHandledError( + test: + (String line) => line.contains('io.flutter.plugin.common.PluginRegistry.Registrar registrar'), + handler: ({ + required String line, + required FlutterProject project, + required bool usesAndroidX, + }) async { + globals.printBox( + ''' +${globals.logger.terminal.warningMark} Consult the error logs above to identify any broken plugins, specifically those containing "error: cannot find symbol..." +This issue is likely caused by v1 embedding removal and the plugin's continued usage of removed references to the v1 embedding. +To fix this error, please upgrade your current package's dependencies to latest versions by running `flutter pub upgrade`. +If that does not work, please file an issue for the problematic plugin(s) here: https://github.com/flutter/flutter/issues''', + title: _boxTitle, + ); + + return GradleBuildStatus.exit; + }, + eventLabel: 'usage-of-v1-embedding-references', +); + @visibleForTesting final GradleHandledError jlinkErrorWithJava21AndSourceCompatibility = GradleHandledError( test: (String line) => line.contains('> Error while executing process') && line.contains('jlink'), diff --git a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart index 4ab85e0f63..cf1ddaf5fe 100644 --- a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart +++ b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart @@ -52,6 +52,7 @@ void main() { remoteTerminatedHandshakeHandler, couldNotOpenCacheDirectoryHandler, incompatibleCompileSdk35AndAgpVersionHandler, + usageOfV1EmbeddingReferencesHandler, jlinkErrorWithJava21AndSourceCompatibility, incompatibleKotlinVersionHandler, ]), @@ -1485,6 +1486,50 @@ ERROR:/Users/mackall/.gradle/caches/transforms-3/bd2c84591857c6d4c308221ffece862 }, ); + testUsingContext( + 'Usage of removed v1 embedding references', + () async { + const String errorExample = r''' +/Users/jesswon/.pub-cache/hosted/pub.dev/video_player_android-2.5.0/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayerPlugin.java:42: error: cannot find symbol + private VideoPlayerPlugin(io.flutter.plugin.common.PluginRegistry.Registrar registrar) { + ^ + symbol: class Registrar + location: interface PluginRegistry +1 error + +FAILURE: Build failed with an exception. + '''; + + final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); + await usageOfV1EmbeddingReferencesHandler.handler( + line: errorExample, + project: project, + usesAndroidX: true, + ); + + // Main fix text. + expect( + testLogger.statusText, + contains( + "To fix this error, please upgrade your current package's dependencies to latest versions by", + ), + ); + expect(testLogger.statusText, contains('running `flutter pub upgrade`.')); + // Text and link to file an issue. + expect( + testLogger.statusText, + contains('If that does not work, please file an issue for the problematic plugin(s) here:'), + ); + expect(testLogger.statusText, contains('https://github.com/flutter/flutter/issues')); + }, + overrides: { + GradleUtils: () => FakeGradleUtils(), + Platform: () => fakePlatform('android'), + FileSystem: () => fileSystem, + ProcessManager: () => processManager, + }, + ); + testUsingContext( 'Java 21 and jlink bug', () async {