isNativeCppModule function
Returns true when the spec file uses direct C++ for Android or Linux —
the platforms that share src/CMakeLists.txt (Android NDK / Linux GCC).
Narrow check — use for:
- Deciding whether
HybridXxx.cppbelongs insrc/CMakeLists.txt - Doctor's "impl file linked" check for the shared cmake target
- Skipping the "unlinked source" warning for Windows-only C++ modules
Implementation
bool isNativeCppModule(File specFile) {
final content = specFile.readAsStringSync();
final annotationMatch = RegExp(r'@NitroModule\s*\(([^)]+)\)', dotAll: true).firstMatch(content);
if (annotationMatch == null) return false;
final annotation = annotationMatch.group(1)!.replaceAll('\n', ' ');
// Only consider Android and Linux — these use src/CMakeLists.txt via NDK/GCC.
return RegExp(
r'\b(?:android|linux)\s*:\s*'
r'(?:NativeImpl|AndroidNativeImpl|LinuxNativeImpl)\.cpp\b',
).hasMatch(annotation);
}