Skip to content
Merged
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
6 changes: 4 additions & 2 deletions packages/cmake-rn/src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export const ANDROID_ARCHITECTURES = {
type AndroidConfigureOptions = {
triplet: AndroidTriplet;
ndkVersion: string;
sdkVersion: string;
};

export function getAndroidConfigureCmakeArgs({
triplet,
ndkVersion,
sdkVersion,
}: AndroidConfigureOptions) {
const { ANDROID_HOME } = process.env;
assert(typeof ANDROID_HOME === "string", "Missing env variable ANDROID_HOME");
Expand Down Expand Up @@ -80,8 +82,8 @@ export function getAndroidConfigureCmakeArgs({
`ANDROID_ABI=${architecture}`,
"-D",
"ANDROID_TOOLCHAIN=clang",
// "-D",
// `ANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL}`,
"-D",
`ANDROID_PLATFORM=${sdkVersion}`,
"-D",
"ANDROID_STL=c++_shared",
// Pass linker flags to avoid errors from undefined symbols
Expand Down
18 changes: 17 additions & 1 deletion packages/cmake-rn/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ EventEmitter.defaultMaxListeners = 100;

// This should match https://github.com/react-native-community/template/blob/main/template/android/build.gradle#L7
const DEFAULT_NDK_VERSION = "27.1.12297006";
const DEFAULT_ANDROID_SDK_VERSION = "24";

// TODO: Add automatic ccache support

Expand Down Expand Up @@ -88,6 +89,11 @@ const ndkVersionOption = new Option(
"The NDK version to use for Android builds"
).default(DEFAULT_NDK_VERSION);

const androidSdkVersionOption = new Option(
"--android-sdk-version <version>",
"The Android SDK version to use for Android builds"
).default(DEFAULT_ANDROID_SDK_VERSION);

const noAutoLinkOption = new Option(
"--no-auto-link",
"Don't mark the output as auto-linkable by react-native-node-api"
Expand Down Expand Up @@ -115,6 +121,7 @@ export const program = new Command("cmake-rn")
.addOption(outPathOption)
.addOption(cleanOption)
.addOption(ndkVersionOption)
.addOption(androidSdkVersionOption)
.addOption(noAutoLinkOption)
.addOption(noWeakNodeApiLinkageOption)
.addOption(xcframeworkExtensionOption)
Expand Down Expand Up @@ -348,12 +355,19 @@ function getTripletBuildPath(buildPath: string, triplet: SupportedTriplet) {

function getTripletConfigureCmakeArgs(
triplet: SupportedTriplet,
{ ndkVersion }: Pick<GlobalContext, "ndkVersion" | "weakNodeApiLinkage">
{
ndkVersion,
androidSdkVersion,
}: Pick<
GlobalContext,
"ndkVersion" | "androidSdkVersion" | "weakNodeApiLinkage"
>
) {
if (isAndroidTriplet(triplet)) {
return getAndroidConfigureCmakeArgs({
triplet,
ndkVersion,
sdkVersion: androidSdkVersion,
});
} else if (isAppleTriplet(triplet)) {
return getAppleConfigureCmakeArgs({ triplet });
Expand All @@ -379,6 +393,7 @@ async function configureProject(context: TripletScopedContext) {
tripletBuildPath,
source,
ndkVersion,
androidSdkVersion,
weakNodeApiLinkage,
} = context;
await spawn(
Expand All @@ -392,6 +407,7 @@ async function configureProject(context: TripletScopedContext) {
...getTripletConfigureCmakeArgs(triplet, {
ndkVersion,
weakNodeApiLinkage,
androidSdkVersion,
}),
],
{
Expand Down
Loading