Repository navigation
Description
Steps to reproduce
- Create the package below (
tiny_native). Its hook bundles a prebuilt dylib, the way packages that wrap closed-source SDKs do. - Run
./make_dylib.sh. It links the dylib with a plainclang -dynamiclib, without-headerpad_max_install_names, which leaves 48 bytes of header padding. - Put the package at a path longer than 31 characters (for example
/Users/me/src/headerpad-repro/tiny_native) and runflutter test. At 31 characters or fewer it passes.
Expected results
The test runs and passes.
The same package works in an app: flutter build macos embeds tiny.framework, and the call returns 5.
Actual results
flutter test exits with code 1 before any test starts (log below).
copyNativeCodeAssetsMacOSFlutterTester sets each code asset's install name to its absolute path under <project>/build/native_assets/macos/. That path grows with the project path. Here it no longer fits in the header, so install_name_tool -id fails, and setInstallNamesDylib turns the failure into a tool exit for the whole run.
Linking the dylib with -headerpad_max_install_names makes the test pass. A package that ships a vendor's prebuilt cannot relink it, though.
Reproduced on 3.47.7 (stable) and 3.50.0-0.1.pre (beta). The tester code is the same on master.
We hit this in flutter_edge_ai_litertlm. The LiteRT-LM companion dylibs we bundle (Google prebuilts) have 64 and 56 bytes of padding, so with them flutter test fails for any project path longer than 43 characters. That is why our package keeps them out of its macOS code assets today. abdelaziz-mahdy/executorch_flutter#51 hit the same with MoltenVK.
Proposal
Change only the tester: when -id does not fit, keep the dylib's own install name and still apply the -changes to its dependents. Print a warning that names the asset and suggests -headerpad_max_install_names.
- Dependents and the manifest both reference the absolute path, and within one
flutter testrun the files are copied once, before any test process starts. The double mapping from # [macOS] Native asset framework is mapped twice after a rebuild, because the manifest path does not match the install name #190799 needs the file to be replaced under a running process, which does not happen here. - Assets whose new name fits keep the guarantee from [native_assets] Record bundled code assets under their install name #190819.
Never rewriting the id in the tester would also work, but it drops that guarantee for everyone.
A PR with the first option follows. I'm happy to switch to the second if you prefer it.
Code sample
Code sample
pubspec.yaml
name: tiny_native
publish_to: none
environment:
sdk: ^3.10.0
flutter: ">=3.38.0"
dependencies:
code_assets: ^1.0.0
flutter:
sdk: flutter
hooks: ^1.0.0
dev_dependencies:
flutter_test:
sdk: fluttersrc/tiny.c
int tiny_add(int a, int b) { return a + b; }make_dylib.sh
#!/bin/sh
set -e
cd "$(dirname "$0")"
mkdir -p prebuilt
clang -arch arm64 -dynamiclib -mmacosx-version-min=11.0 src/tiny.c \
-install_name @rpath/libtiny.dylib -o prebuilt/libtiny.dylibhook/build.dart
import 'dart:io';
import 'package:code_assets/code_assets.dart';
import 'package:hooks/hooks.dart';
void main(List<String> args) async {
await build(args, (input, output) async {
if (!input.config.buildCodeAssets) return;
final source = input.packageRoot.resolve('prebuilt/libtiny.dylib');
final target = input.outputDirectory.resolve('libtiny.dylib');
await File.fromUri(source).copy(target.toFilePath());
output.assets.code.add(
CodeAsset(
package: input.packageName,
name: 'tiny_native.dart',
linkMode: DynamicLoadingBundled(),
file: target,
),
);
output.dependencies.add(source);
});
}lib/tiny_native.dart
import 'dart:ffi';
@Native<Int32 Function(Int32, Int32)>(symbol: 'tiny_add')
external int tinyAdd(int a, int b);test/tiny_native_test.dart
import 'package:flutter_test/flutter_test.dart';
import 'package:tiny_native/tiny_native.dart';
void main() {
test('calls into the bundled dylib', () {
expect(tinyAdd(2, 3), 5);
});
}Logs
Logs
$ flutter test
Failed to change install names in LocalFile: '/Users/sashadenisov/Work/headerpad-repro/tiny_native/build/native_assets/macos/libtiny.dylib':
id -> /Users/sashadenisov/Work/headerpad-repro/tiny_native/build/native_assets/macos/libtiny.dylib
dependencies -> /Users/sashadenisov/Work/headerpad-repro/tiny_native/build/native_assets/macos/libtiny.dylib
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: changing install names or rpaths can't be redone for: /Users/sashadenisov/Work/headerpad-repro/tiny_native/build/native_assets/macos/libtiny.dylib (for architecture arm64) because larger updated load commands do not fit (the program must be relinked, and you may need to use -headerpad or -headerpad_max_install_names)Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.47.7, on macOS 26.5.1 25F80 darwin-arm64, locale en-US) [2.0s]
• Flutter version 3.47.7 on channel stable at /Users/sashadenisov/fvm/versions/3.47.7
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision abaf9c5237 (11 days ago), 2026-10-08 09:51:21 -0700
• Engine revision deb287481e
• Dart version 3.13.5
• DevTools version 2.60.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, no-cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
[!] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [6.0s]
• Android SDK at /Users/sashadenisov/Library/Android/sdk
• Emulator version 36.2.12.0 (build_id 14214601) (CL:N/A)
• Platform android-36, build-tools 36.1.0
! Multiple adb binaries found. This can cause conflicts and device detection issues:
- /Users/sashadenisov/Library/Android/sdk/platform-tools/adb
- /opt/homebrew/Caskroom/android-platform-tools/36.0.0/platform-tools/adb
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 26.5) [3.4s]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 17F42
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [6ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Connected device (4 available) [9.6s]
• [physical iPhone, redacted] (mobile) • [udid] • ios • iOS 26.5.2 23F84
• iPhone 17 Pro (mobile) • 92BF8D58-A06F-4E2E-B280-5917716E7014 • ios • com.apple.CoreSimulator.SimRuntime.iOS-26-5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 26.5.1 25F80 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 155.0.8059.80
[✓] Network resources [351ms]
• All expected network resources are available.
! Doctor found issues in 1 category.
Activity
dcharkes commentedon Oct 20, 2026
This might make your tests work, but it might not work when you try to package up the dylib in the release version of an app (with the xcframework). Or are the paths shorter for the app bundles and this only affects
flutter test?Do things open correctly when you try to not rewrite the name? Often MacOS will block opening the dylib
dlopenwill fail.This SGTM.
Though the current error is already quite understandable right?
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: changing install names or rpaths can't be redone for: /Users/sashadenisov/Work/headerpad-repro/tiny_native/build/native_assets/macos/libtiny.dylib (for architecture arm64) because larger updated load commands do not fit (the program must be relinked, and you may need to use -headerpad or -headerpad_max_install_names)Please file an issue upstream, do they have a bugtracker?
DenisovAV commentedon Oct 20, 2026
It only affects
flutter test. App builds use@rpath/<name>.framework/<name>, which fits: with a dylib that has 48 bytes of padding, a macOS release app, an iOS release build, an iOS simulator run, andflutter build ios-framework/macos-frameworkall work on 3.47.7, and #194802 doesn't touch those paths.And yes, it opens. I applied #194802 to 3.47.7, so the run used the signed stable
flutter_tester. The repro passes, anddlopenby the absolute path works with the old install name, also through a dependent dylib (one copy in the process). Our LiteRT-LM companions load the same way.The error is clear to whoever can relink. An app that depends on a package shipping a vendor prebuilt can't, and today its whole
flutter testfails, even a test that never touches the asset.Upstream: google-ai-edge/LiteRT-LM#2151, filed in May and assigned, no reply yet.
[native_assets] Keep a dylib's install name in flutter test when its …