UnsupportedError: 'Mirrors are not supported.' in dart:mirrors during AOT compilation
0 reputation · 14 Dec 2022, 03:46 UTC
Problem Context
Local development on the Dart VM with JIT compilation permits the use of dart:mirrors for runtime type inspection and dynamic class loading. When the same code is compiled for production using AOT (e.g., flutter build apk --release or dart compile exe), the mirror system is omitted from the binary. Executing the release build immediately throws the documented error:
UnsupportedError: 'Mirrors are not supported.'
This discrepancy surfaces only in release environments, causing silent failures that are hard to diagnose without explicit AOT testing.
Unresolved Decision
The Dart team has not yet committed to a partial mirror implementation for AOT. Developers face a choice: invest in a restricted mirror subset, or continue to rely on static code generation (build_runner) and, in Dart 3, macros for compile‑time introspection.
Targeted Questions
- What are the trade‑offs between adopting a restricted mirror subset versus migrating to static code generation for production Dart applications?
- Can the compiler or build system be enhanced to detect and warn about
dart:mirrorsusage before release packaging? - Will future Dart releases provide any form of partial mirror support for AOT‑compiled binaries?