Issue
Have a pure Dart server app which is currently using 'dart:mirrors' in a class to do a bit of light reflection work at runtime. The server app compiles and runs absolutely fine in development Ubuntu machine with x86 architecture but, the same server app fails to compile as part of a Docker build on an Ubuntu Raspberry pi 4 using latest arm64v8/dart:stable
Docker Image.
Docker build error:
---> Running in e4bdea430736\n\u001b[91merror: import of dart:mirrors is not supported in the current Dart runtime\n\u001b[0m\u001b[91mError: AOT compilation failed\n\u001b[0m\u001b[91mGenerating AOT snapshot failed!\u001b[0m\u001b[91m\n\u001b[0m
Is 'dart:mirrors' not supported in current arm64 architecture version of Dart? Or could the issue be something else?
NOTE: The server app is pure Dart code (i.e. there is no Flutter code being used at all either directly or indirectly via dependencies - as far as I can see).
--- UPDATE ---
Dockerfile compile instructions:
FROM arm64v8/dart:stable AS build
WORKDIR /tmp
RUN dart pub get
RUN dart pub upgrade
RUN dart pub outdated
RUN dart compile exe /example.com/example_api/bin/server.dart -o /example.com/example_api/bin/server
Solution
Self-contained executables (exe) has limitations. One of them is No support for dart:mirrors and dart:developer
Please check the documentation, and you may try the JIT snapshot or the Kernel subcommands, since they do not have that limitation.
Answered By - Vladimir Gadzhov Answer Checked By - Katrina (WPSolving Volunteer)