feat: Support autolinking C++ only TurboModules on Android #2387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
#2296 adds support for auto-linking C++ turbo modules on Android. However, you would still need a
build.gradle
file for your module to be linked. This is for a couple of reasons:AndroidManifest.xml
file or abulid.gradle
file,react-native config
returnsnull
. See the related line.packageName
,react-native config
returnsnull
. We don't need thepackageName
property since C++ projects are included by their paths. See the related line.PackageList.java
file tries to include and initialize your turbo module as a Java class. See the related line.This PR derives a property called
isPureCxxDependency
from a few factors:cxxModuleCMakeListsModuleName
as a truthy value in their configuration.cxxModuleCMakeListsPath
as a truthy value in their configuration.cxxModuleHeaderName
as a truthy value in their configuration.build.gradle
file in theirsourceDir
(This isandroid/
by default) or its subdirectories.AndroidManifest.xml
file in theirsourceDir
or its subdirectories.If all these cases are met, the CLI outputs the
isPureCxxDependency
property astrue
. This in turn causes thenative-modules.gradle
file not to include this dependency in the generatedPackageList.java
file and the dependency isn't added as a gradle dependency to the app project.Test Plan:
I have created a turbo module using create-react-native-library. Then I linked the CLI and tested the implementation. I've also added react-native-reanimated as a dependency to the project's example app to make sure this implementation doesn't break the existing support for turbo modules.
Checklist