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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/cli-platform-android/native_modules.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ class ReactNativeModules {
reactNativeModules.forEach { reactNativeModule ->
def nameCleansed = reactNativeModule["nameCleansed"]
def dependencyConfiguration = reactNativeModule["dependencyConfiguration"]
def isPureCxxDependency = reactNativeModule["isPureCxxDependency"]
if (isPureCxxDependency) {
return
}

appProject.dependencies {
if (reactNativeModulesBuildVariants.containsKey(nameCleansed)) {
reactNativeModulesBuildVariants
Expand Down Expand Up @@ -247,10 +252,14 @@ class ReactNativeModules {
"${prefix}${packageName}.${className}${suffix}"
})
}
packageImports = packages.collect {
packageImports = packages
.findAll { !it.isPureCxxDependency }
.collect {
"// ${it.name}\n${interpolateDynamicValues(it.packageImportPath)}"
}.join('\n')
packageClassInstances = ",\n " + packages.collect {
packageClassInstances = ",\n " + packages
.findAll { !it.isPureCxxDependency }
.collect {
interpolateDynamicValues(it.packageInstance)
}.join(",\n ")
}
Expand Down Expand Up @@ -471,6 +480,7 @@ class ReactNativeModules {
reactNativeModuleConfig.put("cxxModuleCMakeListsModuleName", androidConfig["cxxModuleCMakeListsModuleName"])
reactNativeModuleConfig.put("cxxModuleCMakeListsPath", androidConfig["cxxModuleCMakeListsPath"])
reactNativeModuleConfig.put("cxxModuleHeaderName", androidConfig["cxxModuleHeaderName"])
reactNativeModuleConfig.put("isPureCxxDependency", androidConfig["isPureCxxDependency"])

if (androidConfig["buildTypes"] && !androidConfig["buildTypes"].isEmpty()) {
reactNativeModulesBuildVariants.put(nameCleansed, androidConfig["buildTypes"])
Expand Down
43 changes: 27 additions & 16 deletions packages/cli-platform-android/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,38 @@ export function dependencyConfig(
? path.join(sourceDir, userConfig.manifestPath)
: findManifest(sourceDir);
const buildGradlePath = findBuildGradle(sourceDir, true);

if (!manifestPath && !buildGradlePath) {
const isPureCxxDependency =
userConfig.cxxModuleCMakeListsModuleName != null &&
userConfig.cxxModuleCMakeListsPath != null &&
userConfig.cxxModuleHeaderName != null &&
!manifestPath &&
!buildGradlePath;

if (!manifestPath && !buildGradlePath && !isPureCxxDependency) {
return null;
}

const packageName =
userConfig.packageName || getPackageName(manifestPath, buildGradlePath);
const packageClassName = findPackageClassName(sourceDir);
let packageImportPath = null,
packageInstance = null;

/**
* This module has no package to export
*/
if (!packageClassName) {
return null;
}
if (!isPureCxxDependency) {
const packageName =
userConfig.packageName || getPackageName(manifestPath, buildGradlePath);
const packageClassName = findPackageClassName(sourceDir);

/**
* This module has no package to export
*/
if (!packageClassName) {
return null;
}

const packageImportPath =
userConfig.packageImportPath ||
`import ${packageName}.${packageClassName};`;
packageImportPath =
userConfig.packageImportPath ||
`import ${packageName}.${packageClassName};`;

const packageInstance =
userConfig.packageInstance || `new ${packageClassName}()`;
packageInstance = userConfig.packageInstance || `new ${packageClassName}()`;
}

const buildTypes = userConfig.buildTypes || [];
const dependencyConfiguration = userConfig.dependencyConfiguration;
Expand Down Expand Up @@ -193,5 +203,6 @@ export function dependencyConfig(
cxxModuleCMakeListsModuleName,
cxxModuleCMakeListsPath,
cxxModuleHeaderName,
isPureCxxDependency,
};
}
5 changes: 3 additions & 2 deletions packages/cli-types/src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export type AndroidProjectParams = {

export type AndroidDependencyConfig = {
sourceDir: string;
packageImportPath: string;
packageInstance: string;
packageImportPath: string | null;
packageInstance: string | null;
dependencyConfiguration?: string;
buildTypes: string[];
libraryName?: string | null;
Expand All @@ -35,6 +35,7 @@ export type AndroidDependencyConfig = {
cxxModuleCMakeListsModuleName?: string | null;
cxxModuleCMakeListsPath?: string | null;
cxxModuleHeaderName?: string | null;
isPureCxxDependency?: boolean;
};

export type AndroidDependencyParams = {
Expand Down
Loading