Skip to content

Commit 71a8a86

Browse files
committed
Add Android SDK option
1 parent 5cb8fe8 commit 71a8a86

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/cmake-rn/src/android.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ export const ANDROID_ARCHITECTURES = {
2323
type AndroidConfigureOptions = {
2424
triplet: AndroidTriplet;
2525
ndkVersion: string;
26+
sdkVersion: string;
2627
};
2728

2829
export function getAndroidConfigureCmakeArgs({
2930
triplet,
3031
ndkVersion,
32+
sdkVersion,
3133
}: AndroidConfigureOptions) {
3234
const { ANDROID_HOME } = process.env;
3335
assert(typeof ANDROID_HOME === "string", "Missing env variable ANDROID_HOME");
@@ -80,8 +82,8 @@ export function getAndroidConfigureCmakeArgs({
8082
`ANDROID_ABI=${architecture}`,
8183
"-D",
8284
"ANDROID_TOOLCHAIN=clang",
83-
// "-D",
84-
// `ANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL}`,
85+
"-D",
86+
`ANDROID_PLATFORM=${sdkVersion}`,
8587
"-D",
8688
"ANDROID_STL=c++_shared",
8789
// Pass linker flags to avoid errors from undefined symbols

packages/cmake-rn/src/cli.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ EventEmitter.defaultMaxListeners = 100;
3939

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

4344
// TODO: Add automatic ccache support
4445

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

92+
const androidSdkVersionOption = new Option(
93+
"--android-sdk-version <version>",
94+
"The Android SDK version to use for Android builds"
95+
).default(DEFAULT_ANDROID_SDK_VERSION);
96+
9197
const noAutoLinkOption = new Option(
9298
"--no-auto-link",
9399
"Don't mark the output as auto-linkable by react-native-node-api"
@@ -115,6 +121,7 @@ export const program = new Command("cmake-rn")
115121
.addOption(outPathOption)
116122
.addOption(cleanOption)
117123
.addOption(ndkVersionOption)
124+
.addOption(androidSdkVersionOption)
118125
.addOption(noAutoLinkOption)
119126
.addOption(noWeakNodeApiLinkageOption)
120127
.addOption(xcframeworkExtensionOption)
@@ -348,12 +355,19 @@ function getTripletBuildPath(buildPath: string, triplet: SupportedTriplet) {
348355

349356
function getTripletConfigureCmakeArgs(
350357
triplet: SupportedTriplet,
351-
{ ndkVersion }: Pick<GlobalContext, "ndkVersion" | "weakNodeApiLinkage">
358+
{
359+
ndkVersion,
360+
androidSdkVersion,
361+
}: Pick<
362+
GlobalContext,
363+
"ndkVersion" | "androidSdkVersion" | "weakNodeApiLinkage"
364+
>
352365
) {
353366
if (isAndroidTriplet(triplet)) {
354367
return getAndroidConfigureCmakeArgs({
355368
triplet,
356369
ndkVersion,
370+
sdkVersion: androidSdkVersion,
357371
});
358372
} else if (isAppleTriplet(triplet)) {
359373
return getAppleConfigureCmakeArgs({ triplet });
@@ -379,6 +393,7 @@ async function configureProject(context: TripletScopedContext) {
379393
tripletBuildPath,
380394
source,
381395
ndkVersion,
396+
androidSdkVersion,
382397
weakNodeApiLinkage,
383398
} = context;
384399
await spawn(
@@ -392,6 +407,7 @@ async function configureProject(context: TripletScopedContext) {
392407
...getTripletConfigureCmakeArgs(triplet, {
393408
ndkVersion,
394409
weakNodeApiLinkage,
410+
androidSdkVersion,
395411
}),
396412
],
397413
{

0 commit comments

Comments
 (0)