website/versioned_docs/version-0.80/the-new-architecture/codegen-cli.md
Calling Gradle or manually calling a script might be hard to remember and it requires a lot of ceremony.
To simplify it, we created a CLI tool that can help you running those tasks: the Codegen cli. This command runs @react-native/codegen for your project. The following options are available:
npx @react-native-community/cli codegen --help
Usage: rnc-cli codegen [options]
Options:
--verbose Increase logging verbosity
--path <path> Path to the React Native project root. (default: "/Users/MyUsername/projects/my-app")
--platform <string> Target platform. Supported values: "android", "ios", "all". (default: "all")
--outputPath <path> Path where generated artifacts will be output to.
-h, --help display help for command
package.json from the current working directory, generate code based on its codegenConfig.npx @react-native-community/cli codegen
package.json from the current working directory, generate iOS code in the location defined in the codegenConfig.npx @react-native-community/cli codegen --platform ios
package.json from third-party/some-library, generate Android code in third-party/some-library/android/generated.npx @react-native-community/cli codegen \
--path third-party/some-library \
--platform android \
--outputPath third-party/some-library/android/generated
The Codegen CLI is a great tool for library developers. It can be used to take a sneak-peek at the generated code to see which interfaces you need to implement.
Normally the generated code is not included in the library, and the app that uses the library is responsible for running the Codegen at build time.
This is a good setup for most cases, but Codegen also offers a mechanism to include the generated code in the library itself via the includesGeneratedCode property.
It's important to understand what are the implications of using includesGeneratedCode = true. Including the generated code comes with several benefits such as:
On the other hand, you also need to be aware of one drawback:
includesGeneratedCodeTo enable this setup:
includesGeneratedCode property into your library's codegenConfig field in the package.json file. Set its value to true.package.json to include the generated code.podspec to include the generated code.build.Gradle file to include the generated code.cmakeListsPath in react-native.config.js so that Gradle doesn't look for CMakeLists file in the build directory but instead in your outputDir.