-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Summary
plugin_platform_interface 1.0.0 crashes in release web builds on load, resulting in a blank screen. The error occurs while registering web plugins due to an incorrect token check against MockPlatformInterfaceMixin. plugin_platform_interface is a dependency of at least url_launcher and I believe more plugins to come as web support is rolled out.
Steps to Reproduce
Run
flutter run --release -d chrome
See a blank screen.
Error
In a minified release build, with the error happening on load, there is not much by way of a stack trace to look at, but for what it's worth, here's the error from the error output from the Chrome dev tools console:
Uncaught Assertion failed
at Object.f (http://localhost:1210/main.dart.js:1936:3)
at Object.a1 (http://localhost:1210/main.dart.js:1942:24)
at http://localhost:1210/main.dart.js:14742:3
at ajo.a (http://localhost:1210/main.dart.js:2928:71)
at ajo.$2 (http://localhost:1210/main.dart.js:26462:23)
at Object.C (http://localhost:1210/main.dart.js:2915:19)
at Object.KG (http://localhost:1210/main.dart.js:14749:10)
at http://localhost:1210/main.dart.js:73089:8
at http://localhost:1210/main.dart.js:73084:55
at dartProgram (http://localhost:1210/main.dart.js:73087:84)
When turning on pause on exceptions and looking at the other variables in scope at the time when that assertion failed, there was a more informative error message that pointed me to the problem:
"MockPlatformInterfaceMixin is not intended for use in release builds."
This assertion comes from plugin_platform_interface.dart.
Suspected Cause
As far as I can tell, in release builds, the verifyToken method of PlatformInterface expects the token of the plugin being registered, e.g. UrlLauncherPlatform to be different to the token of MockPlatformInterfacePlugin to ensure mock plugins aren't used in release. However both of these classes create their tokens using static const Object(). This assertion to fail in release builds since all Object instances created with const are identical. See test snippet below for demonstration of const object equality.
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Const objects are equal, non-const objects are not', () {
expect(identical(Object(), Object()), isFalse);
expect(identical(const Object(), const Object()), isTrue);
expect(identical(MyDummyClass.finalFoo, MyDummyClass.finalBar), isFalse);
expect(identical(MyDummyClass.constFoo, MyDummyClass.constBar), isTrue);
});
}
class MyDummyClass {
static const constFoo = Object();
static const constBar = Object();
static final finalFoo = Object();
static final finalBar = Object();
}
Doctor Output
>flutter doctor
flutter doctor -v
[√] Flutter (Channel master, v1.13.3-pre.11, on Microsoft Windows [Version 10.0.18362.535], locale en-AU)
• Flutter version 1.13.3-pre.11 at C:\flutter
• Framework revision 0497235c20 (19 minutes ago), 2019-12-12 19:05:48 -0800
• Engine revision db60ebc632
• Dart version 2.8.0 (build 2.8.0-dev.0.0 d9fa37e85d)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
• Android SDK at C:\Users\Alex\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 42.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
[√] VS Code (version 1.41.0)
• VS Code at C:\Users\Alex\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.7.1
[√] Connected device (3 available)
• SM G975F • R58M20N3HSM • android-arm64 • Android 9 (API 28)
• Chrome • chrome • web-javascript • Google Chrome 79.0.3945.79
• Web Server • web-server • web-javascript • Flutter Tools
• No issues found!
Workaround
For anyone else experiencing this problem, I'm currently using my fork here to work around the issue using a dependency override in my pubspec.yaml
dependency_overrides:
plugin_platform_interface:
git:
url: https://github.com/buntagonalprism/plugins.git
ref: fix-platform-interface-token
path: packages/plugin_platform_interface
I haven't raised a PR because there's an used parameter in verifyToken in my change now, which if removed would have flow on effects to other plugins relying on the platform interface.