How to add closed dynamic libraries to a Flutter app using dart Hooks?
17:11 23 Mar 2026

my environment details:

=== dart info ===
- Dart 3.11.1 (stable) (Tue Feb 24 00:03:07 2026 -0800) on "macos_arm64"
- on macos / Version 26.3.1 (a) (Build 25D771280a)
- locale is en-US

#### Project info

- sdk constraint: '^3.11.1'
- dependencies: code_assets, dart_ipc, data_assets, ffi, flutter, hooks, logging, native_toolchain_c, path
- dev_dependencies: ffigen, flutter_lints, test

=============

My question:

I have integrated my flutter app with Holepunch's bare-kit using ffigen and it executes a simple javascript without a problem.

However, executing a javascript (ipc_test.bundle) that calls Holepunch's 'bare-tcp' npm module fails (see error log below).
The 'bare-tcp' depends on dynamic bare libs, e.g. libbare-dns.2.1.4.dylib.

In my hook build.dart script I add each needed dynamic libs as a CodeAsset, e.g.:

output.assets.code.add(CodeAsset(
    package: input.packageName,
    name: "libbare-dns.2.1.4.so",
    linkMode: DynamicLoadingBundled(),
    file: input.packageRoot.resolve('lib/src/bare/libs/android/arm64/arm64-v8a/libbare-dns.2.1.4.so'),
  )
)

But executing the script leads to a runtime error; it seems that the dynamic lib cannot be loaded.
See the error log below and a screenshot from Android Studio showing the apk contents.
Can anybody explain what I am doing wrong?

Thanks in advance

ERROR LOG:

E/xample.bare_kit( 3780): Uncaught (in promise) AddonError: ADDON_NOT_FOUND: Cannot find addon '.' imported from 'file:///app.bundle/node_modules/bare-dns/binding.js'  
E/xample.bare_kit( 3780): Candidates:  
E/xample.bare_kit( 3780): - linked:libbare-dns.2.1.4.dylib  
E/xample.bare_kit( 3780):     at Addon.resolve (bare:/bare.js:3535:22)  
E/xample.bare_kit( 3780):     at require.addon (bare:/worklet.bundle/node_modules/bare-module/index.js:776:33)  
E/xample.bare_kit( 3780):     at file:///app.bundle/node_modules/bare-dns/binding.js:1:26   
E/xample.bare_kit( 3780):     at Module.\_evaluate (bare:/worklet.bundle/node_modules/bare-module/index.js:210:7)  
E/xample.bare_kit( 3780):     at Module.\_transform (bare:/worklet.bundle/node_modules/bare-module/index.js:122:12)  
E/xample.bare_kit( 3780):     at Module.load (bare:/worklet.bundle/node_modules/bare-module/index.js:467:21)  
E/xample.bare_kit( 3780):     at require (bare:/worklet.bundle/node_modules/bare-module/index.js:763:25)  
E/xample.bare_kit( 3780):     at file:///app.bundle/node_modules/bare-dns/index.js:1:17  
E/xample.bare_kit( 3780):     at Module.\_evaluate (bare:/worklet.bundle/node_modules/bare-module/index.js:210:7)  
E/xample.bare_kit( 3780):     at Module.\_transform (bare:/worklet.bundle/node_modules/bare-module/index.js:122:12) {  
E/xample.bare_kit( 3780):   \[cause\]: Error: dlopen failed: library "libbare-dns.2.1.4.dylib

Android Studio screenshot of the apk contents

flutter dart hook dylib