flutterdartobjectboxflutter-objectbox

Error: The method 'getInvocation' isn't defined for the type 'DartObjectImpl'


Android Studio Latest, Flutter 3.35.6, sdk: ^3.9.2, Microsoft Windows 11 25H2, Flutter Doctor without warnings.

Create a new Flutter project (Android & iOS) and without touching the generated code, issue these commands:

flutter packages upgrade
flutter pub add objectbox objectbox_flutter_libs:any
flutter pub add --dev build_runner objectbox_generator:any
flutter packages upgrade

this is the output:

Downloading packages...
  build 3.1.0 (4.0.2 available)
  build_resolvers 3.0.3 (3.0.4 available)
  build_runner 2.7.1 (2.9.0 available)
  build_runner_core 9.3.1 (9.3.2 available)
  characters 1.4.0 (1.4.1 available)
  material_color_utilities 0.11.1 (0.13.0 available)
  meta 1.16.0 (1.17.0 available)
  source_gen 3.1.0 (4.0.2 available)
  test_api 0.7.6 (0.7.7 available)
No dependencies changed.
9 packages have newer versions incompatible with dependency constraints.

This is the flutter pub outdated output:

Showing outdated packages.
[*] indicates versions that are not the latest available.

Package Name              Current  Upgradable  Resolvable  Latest

direct dependencies: all up-to-date.

dev_dependencies:
build_runner              *2.7.1   *2.7.1      *2.7.1      2.9.0

transitive dependencies:
characters                *1.4.0   *1.4.0      *1.4.0      1.4.1
material_color_utilities  *0.11.1  *0.11.1     *0.11.1     0.13.0
meta                      *1.16.0  *1.16.0     *1.16.0     1.17.0

transitive dev_dependencies:
build                     *3.1.0   *3.1.0      *3.1.0      4.0.2
build_resolvers           *3.0.3   *3.0.3      *3.0.3      3.0.4   (discontinued)
build_runner_core         *9.3.1   *9.3.1      *9.3.1      9.3.2   (discontinued)
source_gen                *3.1.0   *3.1.0      *3.1.0      4.0.2
test_api                  *0.7.6   *0.7.6      *0.7.6      0.7.7
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.

build_resolvers
    Package build_resolvers has been discontinued. See https://dart.dev/go/package-discontinue
build_runner_core
    Package build_runner_core has been discontinued. See https://dart.dev/go/package-discontinue

When I try to build something with dart run build_runner build I get the following error:

Building package executable... (3.6s)
Built build_runner:build_runner.
Compiling the build script.                                                                                                                                      
                                                                                                                                                                 
log output for build_runner                                                                                                                                      
W ../../AppData/Local/Pub/Cache/hosted/pub.dev/source_gen-3.1.0/lib/src/constants/revive.dart:82:40: Error: The method 'getInvocation' isn't defined for the     
  type 'DartObjectImpl'.                                                                                                                                         
   - 'DartObjectImpl' is from 'package:analyzer/src/dart/constant/value.dart'                                                                                    
  ('../../AppData/Local/Pub/Cache/hosted/pub.dev/analyzer-8.4.0/lib/src/dart/constant/value.dart').                                                              
  Try correcting the name to the name of an existing method, or defining a method named 'getInvocation'.                                                         
    final i = (object as DartObjectImpl).getInvocation();                                                                                                        
                                         ^^^^^^^^^^^^^                                                                                                           
E Failed to compile build script. Check builder definitions and generated script .dart_tool/build/entrypoint/build.dart.

Any other flutter functionality works fine.

Any help would be appreciated
Thanks.


Solution

  • Main problem is analyzer in version 8.4. you must downgrade to 8.3.

    Run

    dart pub downgrade analyzer

    and now command

    dart run build_runner build

    works!