commands/link_command library

Classes

LinkCommand
LinkResult
LinkStep
LinkStepRow
LinkView
ManagedContentIssue
A single piece of managed content that is missing from a native plugin file.
ModuleInfo
Module descriptor.
PlatformTargetAnalyzer
Parses the @NitroModule(...) annotation from a spec file once and exposes typed query methods for each platform target.

Functions

cleanRedundantIncludes(File file) → void
computeLinkSpecChecksum({String baseDir = '.'}) String
createSharedHeaders(String nitroNativePath, {String baseDir = '.'}) → void
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>>
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.
extractLibNameFromSpec(File specFile) String?
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).
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.
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.
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.
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
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 cpp module lib. cpp modules use __attribute__((constructor)) for auto-registration, so no JniBridge.register call is needed — just loading the .so is enough.
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.
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.
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.
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.
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.