Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support autolinking C++ only TurboModules on Android #2387

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

atlj
Copy link

@atlj atlj commented May 10, 2024

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:

  1. If the module doesn't have a valid AndroidManifest.xml file or a bulid.gradle file, react-native config returns null. See the related line.
  2. If your code doesn't have a valid packageName, react-native config returns null. We don't need the packageName property since C++ projects are included by their paths. See the related line.
  3. The native-modules.gradle file tries to add your turbo module as a gradle dependency without checking if it's a valid gradle project. See the related line.
  4. The generated 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:

  1. The user should define cxxModuleCMakeListsModuleName as a truthy value in their configuration.
  2. The user should define cxxModuleCMakeListsPath as a truthy value in their configuration.
  3. The user should define cxxModuleHeaderName as a truthy value in their configuration.
  4. The user shouldn't have a build.gradle file in their sourceDir (This is android/ by default) or its subdirectories.
  5. The user shouldn't have a AndroidManifest.xml file in their sourceDir or its subdirectories.

If all these cases are met, the CLI outputs the isPureCxxDependency property as true. This in turn causes the native-modules.gradle file not to include this dependency in the generated PackageList.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

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md

@github-actions github-actions bot added docs Documentation change feature labels May 10, 2024
@atlj atlj changed the title feat: Support autolinking C++ only native modules on Android feat: Support autolinking C++ only TurboModules on Android May 10, 2024
@cortinico
Copy link
Member

Thanks for sending this over @atlj this is great!

platforms.android.cxxOnly

I think we should not add a new property, and instead adapt the logic to work on the existing properties:

  cxxModuleCMakeListsModuleName?: string | null;
  cxxModuleCMakeListsPath?: string | null;
  cxxModuleHeaderName?: string | null;

and remove the assumption that there needs to be a *Package file.

@atlj
Copy link
Author

atlj commented May 11, 2024

Hey @cortinico I've removed the property from the config. The CLI now treats a dependency that doesn't have a manifest or a build.gradle file (full details in the description) as a pure cxx dependency.

@cortinico
Copy link
Member

Hey @cortinico I've removed the property from the config. The CLI now treats a dependency that doesn't have a manifest or a build.gradle file (full details in the description) as a pure cxx dependency.

Thanks for the sending this over. I'll try to review this in the next days. Just a heads up that things are slower than usual those days due to https://conf.react.dev/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation change feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants