commands/link_command
library
Functions
-
androidEagerLibs(List<ModuleInfo> modules, Set<String> androidCppLibs, {String baseDir = '.'})
→ List<String>
-
The libraries the Kotlin plugin loads when the app starts: Kotlin modules
(their JniBridge needs the library's JNI exports). An Android C++ module is
left to Dart's
DynamicLibrary.open on first use, which also runs its
static constructors (where the impl registers), so the app does not pay
~0.8 ms per library before its first frame. ART resolves external
functions only in libraries System.loadLibrary loaded, so a plugin whose
own C/C++ sources define JNI entry points keeps every library eager.
-
cleanRedundantIncludes(File file)
→ void
-
-
computeLinkSpecChecksum({String baseDir = '.'})
→ String
-
-
-
declaresNitroModule(String source)
→ bool
-
The annotation itself, not a mention in a comment ("type-only, no @NitroModule").
-
describeDuplicateSpecTypes(Map<String, List<File>> dups, String baseDir)
→ List<String>
-
One line per duplicated type, paths relative to
baseDir.
-
desktopPluginClassIsReal(String baseDir, String platform, String pluginClass)
→ bool
-
True when
pluginClass is backed by a real implementation under
<baseDir>/<platform>/ — i.e. the platform sources define the exact
symbol Flutter's generated_plugin_registrant will call:
windows → <PluginClass>RegisterWithRegistrar,
linux → <snake_case(PluginClass)>_register_with_registrar.
A dangling templated class (issue #10) has no such symbol and must be
stripped, or CMake fails with "No target <plugin>_plugin". A hand-written
hybrid plugin (ffiPlugin: true PLUS pluginClass — e.g. FFI bindings
with a texture-registrar plugin class) defines it, and stripping the
entry silently empties the registrant at runtime (issue #23).
-
detectManagedContentIssues({String baseDir = '.'})
→ List<ManagedContentIssue>
-
Scans Plugin.kt and Plugin.swift for managed sections (JniBridge import,
register() call, Registry.register) that are expected for non-cpp modules
but are currently missing. Returns each gap as a ManagedContentIssue.
-
discoverModuleInfos(String pluginName, {String baseDir = '.'})
→ List<ModuleInfo>
-
-
discoverModules(String pluginName, {String baseDir = '.'})
→ List<Map<String, String>>
-
-
duplicateSpecTypes(Directory libDir)
→ Map<String, List<File>>
-
Bridge types (
@HybridStruct, @HybridRecord, @HybridEnum,
@NitroVariant, @NitroCustomType) declared in more than one .native.dart
under libDir, with the files declaring each. Both specs compile into one
Dart library export and one Swift module, so the build fails later with an
"ambiguous" error far from the cause.
-
ensureIosPackageSwift(String pluginName, {String baseDir = '.', List<ModuleInfo>? moduleInfos})
→ void
-
-
ensureMacosPackageSwift(String pluginName, {String baseDir = '.', List<ModuleInfo>? moduleInfos})
→ void
-
Mirrors ensureIosPackageSwift for
macos/. Creates the Flutter 3.41+
nested SPM layout (macos/<pluginName>/Package.swift) if not present,
then syncs C/C++ module sources into SPM Sources directories.
-
-
findPodfileDirs(String projectRoot)
→ List<String>
-
Returns directories containing a Podfile, searching common locations:
<root>/ios/, <root>/macos/, <root>/example/ios/, <root>/example/macos/,
and any direct child */ios/ or */macos/.
-
generateCMake(String pluginName, List<String> moduleLibs, String nitroNativePath, {String baseDir = '.', List<ModuleInfo>? moduleInfos})
→ void
-
-
hasCustomPlatformImpl(String baseDir, String platform, String className)
→ bool
-
Whether Windows or Linux should get its OWN impl file instead of sharing
src/Hybrid$className.cpp — driven entirely by what's actually on disk,
not by annotation config, so both "keep everything in one shared file"
and "diverge Windows and Linux" stay available as a plugin-author choice
(some plugins want one file for easier maintenance when the logic really
is identical; others want Windows and Linux to genuinely diverge — e.g.
different threading primitives, platform intrinsics).
-
hasGeneratedNativeAssetsHook(String baseDir)
→ bool
-
True if
<baseDir>/hook/build.dart exists and is nitrogen-generated (carries
the "GENERATED BY nitrogen" sentinel) — i.e. a native-assets code-asset hook.
-
hookDeclaresCodeAsset(String baseDir)
→ bool
-
True if
hook/build.dart declares a CodeAsset — generated OR hand-written
(e.g. nitro_server's prebuilt downloader). Such a hook delivers the library,
so a platform that also builds the engine double-bundles.
-
injectNativeAssetsPubspecDeps(String pubspecPath, {Map<String, String>? deps})
→ bool
-
Adds any missing
deps (default nativeAssetsHookDeps) under the
dependencies: block of the pubspec at pubspecPath. Returns true if the
file was changed. The external-cmake hook passes only {hooks, code_assets}
(it has no CBuilder, so native_toolchain_c — which pins hooks ^2.x — must
not be forced onto a hooks ^1.x plugin).
-
isAndroidCppModule(File specFile)
→ bool
-
Returns true ONLY when the spec declares
android: NativeImpl.cpp (or AndroidNativeImpl.cpp).
Unlike isNativeCppModule this does NOT match linux-only C++ modules.
-
isAndroidKotlinModule(File specFile)
→ bool
-
Returns true when the module has a Kotlin implementation on Android and
so needs a
JniBridge.registerFactory() call in Plugin.kt. Not the inverse
of isAndroidCppModule: a module that does not target Android (macOS-only,
desktop-only) is neither, and has no JniBridge to register. A spec that is
not found, or declares nothing, keeps the Kotlin default.
-
isAppleCppModule(File specFile)
→ bool
-
Returns true when the spec file uses direct C++ for Apple platforms (ios or macos).
Only Apple C++ modules need a
HybridXxx.cpp forwarder in ios/Classes/ or
macos/Classes/ so CocoaPods compiles the implementation into the pod target.
-
isCppModule(File specFile)
→ bool
-
Returns true when the spec file declares at least one platform as a
direct C++ implementation (no JNI/Swift bridge). Recognises both:
-
isIosCppModule(File specFile)
→ bool
-
Returns true when the spec file uses direct C++ specifically for iOS.
Use this instead of isAppleCppModule when deciding whether the iOS Swift
Plugin.swift needs a
Registry.register() call — a mixed module with
ios: swift, macos: cpp still needs the iOS Swift registration.
-
isIosSwiftModule(File specFile)
→ bool
-
Returns true when the module has a Swift implementation on iOS and so
needs a
Registry.register() call in the iOS Plugin.swift. Not the inverse
of isIosCppModule: a module that targets no Apple platform is neither.
A spec that is not found, or declares nothing, keeps the Swift default.
-
isLinuxCppModule(File specFile)
→ bool
-
Returns true when the spec file uses direct C++ for Linux. A Linux-C++
module always gets a
linux/src/HybridXxx.cpp starter stub created (see
linkLinuxCppImplStubs) — whether it's actually USED instead of the
shared src/HybridXxx.cpp is a separate, opt-in decision driven by file
content (see hasCustomPlatformImpl), independent of Windows.
-
isMacosCppModule(File specFile)
→ bool
-
Returns true when the spec file uses direct C++ specifically for macOS.
Use this instead of isAppleCppModule when deciding whether the macOS Swift
Plugin.swift needs a
Registry.register() call — a mixed module with
ios: cpp, macos: swift still needs the macOS Swift registration.
-
isMacosSwiftModule(File specFile)
→ bool
-
Returns true when the module has a Swift implementation on macOS.
-
isNativeCppModule(File specFile)
→ bool
-
Returns true when the spec file uses direct C++ for Android or Linux —
the platforms that share
src/CMakeLists.txt (Android NDK / Linux GCC).
-
isWindowsCppModule(File specFile)
→ bool
-
Returns true when the spec file uses direct C++ for Windows only.
Windows C++ modules use
windows/CMakeLists.txt (not the shared src/)
and need their own impl stub created in windows/src/.
-
linkAndroid(String pluginName, List<String> moduleLibs, {String baseDir = '.', List<ModuleInfo>? moduleInfos})
→ void
-
Configures
android/build.gradle (or .kts) so the generated Kotlin bridge
files in lib/src/generated/kotlin/ are compiled as part of the Android build.
-
linkAndroidConsumerRules(List<Map<String, String>> kotlinModules, {String baseDir = '.'})
→ void
-
-
linkAndroidLoads(List<ModuleInfo> modules, Set<String> androidCppLibs, String baseDir)
→ void
-
Loads Kotlin modules' libraries when the app starts and drops the eager
load of the others (see androidEagerLibs).
-
linkAndroidModules(String pluginName, List<ModuleInfo> modules, Set<String> androidCppLibs, String baseDir)
→ List<Map<String, String>>
-
The Kotlin plugin's side of every module: JniBridge registration and
Activity forwarding for Kotlin modules, the libraries loaded at start, and
no registration left for a module that is C++ on Android (or not there).
androidCppLibs: the modules with no Kotlin side on Android.
Returns the Kotlin modules.
-
linkBuildYamlSourcesExcludes({String baseDir = '.'})
→ void
-
Writes/patches
android/consumer-rules.pro with the R8/ProGuard keep
rules every Kotlin-on-Android Nitro module needs.
-
linkClangd(String pluginName, {List<ModuleInfo>? moduleInfos, String baseDir = '.'})
→ void
-
-
linkCMake(String pluginName, List<String> moduleLibs, String nitroNativePath, {String baseDir = '.', List<ModuleInfo>? moduleInfos})
→ void
-
-
linkCppImplStubs(List<ModuleInfo> moduleInfos, {String baseDir = '.'})
→ void
-
Builds the
#if guard condition that determines on which platforms the
auto-register call should fire inside a src/HybridXxx.cpp stub.
For each NativeImpl.cpp module that targets Android, Linux, iOS, or macOS,
creates a starter src/Hybrid${Module}.cpp stub if one doesn't already exist.
-
linkDesktopPubspecFfiOnly(List<ModuleInfo> moduleInfos, {String baseDir = '.'})
→ void
-
-
linkKotlinLoadLibraries(List<String> libs, {String baseDir = '.'})
→ void
-
Ensures
System.loadLibrary("lib") is present in the Kotlin plugin's
companion object init block for each lib in libs.
-
linkKotlinPlugin(String pluginName, List<Map<String, String>> modules, {String baseDir = '.'})
→ void
-
-
linkLinux(String pluginName, List<String> moduleLibs, String nitroNativePath, {String baseDir = '.', List<ModuleInfo>? moduleInfos})
→ void
-
-
linkLinuxCppImplStubs(List<ModuleInfo> moduleInfos, {String baseDir = '.'})
→ void
-
Creates a Linux-specific C++ impl starter stub for every Linux-C++
module, mirroring linkWindowsCppImplStubs. Writing this stub does NOT
by itself make Linux use it instead of the shared
src/HybridXxx.cpp —
that's a separate, opt-in decision (see hasCustomPlatformImpl and
ModuleInfo.linuxRequestsSeparateImpl, read by _linkDesktopCMake). Until
then it just sits alongside the shared file as an option, same as
Windows's stub always has.
-
linkMacosPodspec(String pluginName, List<String> moduleLibs, {String baseDir = '.', List<ModuleInfo>? moduleInfos})
→ void
-
-
linkMacosSwiftPlugin(String pluginName, List<Map<String, String>> modules, {String baseDir = '.'})
→ void
-
Wires non-cpp module registrations into the macOS Swift plugin file.
-
linkNativeAssetsHook(List<ModuleInfo> moduleInfos, String nitroNativePath, {String baseDir = '.'})
→ bool
-
Writes
hook/build.dart, vendors nitro's C sources/headers into
src/nitro_native/, and injects the hook deps into pubspec.yaml for the
all-C++ modules in moduleInfos.
-
linkNativeImplStarters({String baseDir = '.'})
→ Set<String>
-
Writes missing Swift and Kotlin impl classes. Returns the Apple platforms
(
ios/macos) that received a new file (their SwiftPM sources need a resync).
-
linkPodspec(String pluginName, List<String> moduleLibs, {String baseDir = '.', List<ModuleInfo>? moduleInfos})
→ void
-
-
linkSwiftPlugin(String pluginName, List<Map<String, String>> modules, {String baseDir = '.'})
→ void
-
-
linkWeb(String pluginName, List<ModuleInfo> moduleInfos, {String? baseDir})
→ int
-
Writes/refreshes
web/build_web.sh for the web-targeting modules and
ensures the assets/web/ asset directory exists. No-op (removes nothing)
when no module targets web.
-
linkWindows(String pluginName, List<String> moduleLibs, String nitroNativePath, {String baseDir = '.', List<ModuleInfo>? moduleInfos})
→ void
-
-
linkWindowsCppImplStubs(List<ModuleInfo> moduleInfos, {String baseDir = '.'})
→ void
-
Creates Windows-specific C++ impl stub files for modules that target
windows: WindowsNativeImpl.cpp. These stubs live in windows/src/ so
windows/CMakeLists.txt can reference them via a relative path.
-
moduleSpecFiles(Directory libDir)
→ List<File>
-
.native.dart files under libDir that declare a @NitroModule. Type-only
files (shared @HybridStruct/@HybridEnum/@HybridRecord) are not modules: no
registry, JNI bridge, SwiftPM target or CMake library of their own.
-
nativeBuildPlatforms(String pubspecContent)
→ List<String>
-
Platforms under
flutter.plugin.platforms that build the engine themselves
(ffiPlugin: true or a pluginClass:) — the ones that double-bundle with a
code asset. Ignores comment lines; web has no native build.
-
purgeStaleCppKotlinRegistrations(List<ModuleInfo> cppModules, {String baseDir = '.'})
→ void
-
Removes stale
<Module>JniBridge.register(...) calls from Plugin.kt for
modules that have been converted to NativeImpl.cpp.
-
purgeStaleCppSwiftRegistrations(List<ModuleInfo> cppModules, {String platform = 'ios', String baseDir = '.'})
→ void
-
Removes stale
<Module>Registry.register(...) calls from *Plugin.swift for
modules that have been converted to NativeImpl.cpp (AppleNativeImpl.cpp).
-
readBridgeChecksum(String baseDir, String lib)
→ String?
-
The generator's compile-time bridge checksum for
lib, read out of the
generated C++ that em++ compiles. Deliberately READ rather than recomputed:
a second implementation of bridgeSpecChecksum in the CLI would drift from
the generator's and report mismatches that do not exist.
-
removeStaleNativeAssetsHook(String baseDir)
→ List<String>
-
Removes a stale generated hook (+ vendored runtime) when the plugin is no
longer on the native-assets path, so it can't double-bundle with the
_dylib
build. Sentinel-gated (never touches a hand-written hook). Returns the
removed paths, relative to baseDir.
-
resolveNitroNativePath(String pluginDir)
→ String
-
Resolves the absolute path to the installed
nitro package's src/native
directory by reading .dart_tool/package_config.json inside pluginDir.
-
stampedBridgeChecksums(String scriptContent)
→ Map<String, String>
-
The checksums
scriptContent was stamped with, keyed by lib.
-
syncSwiftBridgesToSpmSourcesForTest(String baseDir)
→ void
-
Test-only entry point for
_syncSwiftBridgesToSpmSources (GitHub #62
regression coverage). Not part of the public CLI surface.
-
Generated C headers of type-only spec files. Every module bridge that uses
their shared types
#includes them, so each C++ include dir needs a copy.
-
unlinkKotlinLoadLibraries(List<String> libs, {String baseDir = '.'})
→ void
-
Removes
System.loadLibrary("lib") for libs from the Kotlin plugin: an
earlier link loaded every module eagerly (see androidEagerLibs).
-
webBuildScriptTemplate(List<String> webLibs, {Map<String, String>? bridgeChecksums, Set<String> webSpecificImpls = const {}})
→ String
-
The em++ invocation per web-targeting module. Flag set verified by the
nitro web e2e suite:
-
webImplStarterContent(String baseDir, String lib)
→ String
-
Content for a NEW
web/src/Hybrid<Class>.cpp: the generator's starter
(<lib>.impl.g.cpp — every method with its signature) when generate has
produced one, the bare class otherwise. Both carry the shared-impl marker.
-
webSpecificImplPath(String lib)
→ String
-
Relative path of the module's web-specific impl, as
build_web.sh spells it.
-
webUsesSpecificImpl(String baseDir, String lib)
→ bool
-
True when webSpecificImplPath holds real code — the same on-disk test the
desktop CMakeLists use, so an untouched or comments-only stub keeps sharing.
-
writeImplStarters(String pluginName, List<ModuleInfo> moduleInfos, {String baseDir = '.'})
→ void
-
linkNativeImplStarters, then resyncs SwiftPM sources on the Apple
platforms that got a new file (the sync ran before registrations existed).