Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support / documentation for native assets in pub executables #1575

Open
jackd opened this issue Sep 18, 2024 · 1 comment
Open

Add support / documentation for native assets in pub executables #1575

jackd opened this issue Sep 18, 2024 · 1 comment

Comments

@jackd
Copy link

jackd commented Sep 18, 2024

I'm looking for a way to use native assets in a pub-configured executable.

I apologise in advance if this is already implemented / documented somewhere, but having tried to minimally change the native_add_app example I haven't had much luck.

Steps to reproduce:

  1. run dart pub get in native_add_app and native_add_library
  2. add the following to native_add_app/pubspec.yaml:
executables:
  native_add_app:
  1. activate the package globally
dart pub global activate --source path ./native_add_app
  1. Run
native_add_app

Result:

$ native_add_app
Building package executable...
Built native_add_app:native_add_app.
Invoking a native function to calculate 1 + 2.
Unhandled exception:
Invalid argument(s): Couldn't resolve native function 'add' in 'package:native_add_library/native_add_library.dart' : No asset with id 'package:native_add_library/native_add_library.dart' found. No available native assets. Attempted to fallback to process lookup. /home/jackd/programs/flutter/bin/cache/dart-sdk/bin/dart: undefined symbol: add.

#0      Native._ffi_resolver.#ffiClosure0 (dart:ffi-patch/ffi_patch.dart)
#1      Native._ffi_resolver_function (dart:ffi-patch/ffi_patch.dart:1523:20)
#2      add (package:native_add_library/native_add_library.dart)
#3      main (file:///home/jackd/Development/dart/native/pkgs/native_assets_cli/example/build/native_add_app/bin/native_add_app.dart:9:18)
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#5      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
@jackd
Copy link
Author

jackd commented Sep 21, 2024

Managed to get things working with

dart pub global run --enable-experiment=native-assets native_add_app:native_add_app

Not quite as convenient as native_add_app but I can't see any way to make the script pub makes at ~/.pub-cache/bin/native_add_app play nicely.

Having said that, it would be nice if the error message was a little more informative. If I dart run bin/native_add_app I get the much more helpful message:

Package(s) native_add_library require the native assets feature to be enabled. Enable native assets with `--enable-experiment=native-assets`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant