Open derrickgw opened 5 months ago
➤ PM Bot commented:
Jira ticket: RDART-994
you must rename $Test
to _Test
.
Model class must start with _
@jankuo and @derrickgw You can name the model $Test
. Actually it is needed for cross-file links.
@derrickgw Is the above short snippet enough to reproduce the issue for you? What version of realm
are you using?
As a workaround, can you try to delete the .dart_tool
folder, and try again?
@jankuo I was also surprised that $Test
was legal.
@nielsenko I have seen the error even with this small example. I am sure that deleting .dart_tool folder would work. Simply changing the file and running build_runner again will clear the error. I have seen the error with both 1.6 and 2.0.
I recognize that it is hard to track down intermittent errors like this. Is there any sort of extra debugging or logging I can turn on to get more information?
@derrickgw I believe it is an issue with the analyzer
package, or our use of it. If you check your pubspec.lock
what version of the analyzer
are you currently using?
I don't rely directly on analyzer. It looks like I am using 6.2. I can try explicitly referencing it and upgrading to 6.4 to see if that has an impact.
I upgraded flutter and analyzer to the latest, and was still able to get the error:
deleting .dart_tool almost makes it happen reliably on the 2nd build. I wrote a test script and attached the output.
#!/bin/sh -x
rm -r .dart_tool/
for ii in $(seq 1 4); do
echo $ii
date
echo >> lib/model.dart
dart run build_runner build --delete-conflicting-outputs -v || dart run build_runner build --delete-conflicting-outputs -v
date
head -n -1 lib/model.dart > model.dart; mv model.dart lib/model.dart;
dart run build_runner build --delete-conflicting-outputs -v || dart run build_runner build --delete-conflicting-outputs -v
done;
@derrickgw Thanks! I'll try to reproduce on my end.
@derrickgw I managed to hit the issue. Now I "just" need to figure out why.
This issue also occurs with the latest realm 2.0 / flutter 3.19.5.
There is a workaround, in the source file that defines the schema, import realm_common
(direct package contains the annotation) , like this:
import 'package:realm/realm.dart';
+++ import 'package:realm_common/realm_common.dart';
Second build runs well after this change, no more dart run build_runner clean
required.
Don't forget flutter pub add -d realm_common
to add realm_common
as dev dependency.
Maybe dart codegen does not support indirect package import when caching?
Riverpod
also has a separate package riverpod_annotation but I didn't find info related to build error in the commit history.
Riverpod requires adding riverpod_annotation
as dependency in doc Get Started
This issue also occurs with the latest realm 2.0 / flutter 3.19.5.
There is a workaround, in the source file that defines the schema, import
realm_common
(direct package contains the annotation) , like this:import 'package:realm/realm.dart'; +++ import 'package:realm_common/realm_common.dart';
Second build runs well after this change, no more
dart run build_runner clean
required.Don't forget
flutter pub add -d realm_common
to addrealm_common
as dev dependency.
realm: ^2.3.0 has same issue and this solution worked.
What happened?
Every so often, the build generator throws an error on the Annotation. I estimate this happens 1 out of 10 times.
I have also noticed that when it happens the build running tries to execute a few thousand steps instead of a few hundred. When it is in this state, rerunning it doesn't fix it. I have to modify the file (usually I add an extra newline) for it to run correctly.
Repro steps
Run the buildrunner. Every so often it will crash on the first insatnce of
@RealmObject()
in the file.Version
Dart 3.2.6/Flutter 3.16.9
What type of application is this?
Flutter Application
Client OS and version
Ubuntu 20.04.4 LTS
Code snippets
Stacktrace of the exception/crash you're getting
Relevant log output