Configuration (nitro.json)
Nitrogen requires a nitro.json file to be configured at the root of each
Nitro Module.
{
"$schema": "https://nitro.margelo.com/nitro.schema.json",
"environment": "react-native",
"cxxNamespace": ["$$cxxNamespace$$"],
"apple": {
"moduleName": "$$appleModuleName$$"
},
"android": {
"namespace": ["$$androidNamespace$$"],
"cxxLibName": "$$androidCxxLibName$$"
},
"ignorePaths": ["**/node_modules"]
}
Nitrogen parses this file with Zod, see
NitroUserConfig.ts for more information.
environment
Selects the package that generated JavaScript code imports Nitro APIs from:
"react-native"(default): imports fromreact-native-nitro-modules, which installs Nitro in the React Native runtime."bare": imports fromnitro-corefor standalone runtimes.
This setting only changes the JavaScript imports. Native code generation is the same for both environments.
cxxNamespace
The cxxNamespace is the C++ namespace that all C++ specs will be generated in. It is always relative to margelo::nitro, and can also
have multiple sub-namespaces:
{
"cxxNamespace": ["math", "extra"]
}
namespace margelo::nitro::math::extra {
// ...generated classes
}
apple
Settings for the Apple platforms: iOS, macOS, tvOS and visionOS.
moduleName
The moduleName names the generated Swift module for CocoaPods and Swift Package Manager, and the SwiftPM library product. Libraries that
support SwiftPM must use the same name in swiftpmConfig:
{
"apple": {
"moduleName": "NitroMath"
}
}
{
"swiftpmConfig": {
"name": "NitroMath",
"dependencies": ["react-native-nitro-modules"]
}
}
See Nitrogen's build setup for CocoaPods, Package.swift and generated
source configuration.
android
Settings specifically for the Android platform.
namespace
The namespace represents the package namespace in which all Java/Kotlin files are generated and written in. Similar to the cxxNamespace,
this is always relative to com.margelo.nitro, and can also have multiple sub-namespaces.
In most cases, keep it in sync with the namespace in your build.gradle, which holds the full package (com.margelo.nitro.math.extra).
{
"android": {
"namespace": ["math", "extra"]
}
}
package com.margelo.nitro.math.extra
// ...
cxxLibName
The cxxLibName represents the name of the native C++ library that JNI will load to connect Java/Kotlin to C++.
When this Nitro Module is using CMake, this is the same thing as the library defined in CMakeLists.txt.
Nitro will load this library at runtime using System.loadLibrary.
{
"android": {
"cxxLibName": "NitroMath"
}
}
project(NitroMath)
add_library(NitroMath SHARED
src/main/cpp/cpp-adapter.cpp
../cpp/HybridMath.cpp
)
ignorePaths
Configures the TypeScript parser to ignore specific given paths when looking for *.nitro.ts specs.
By default, this is empty ([]), but it can be set to ignore paths like ["node_modules", "lib"].