-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathandroid.ts
More file actions
89 lines (79 loc) · 2.28 KB
/
android.ts
File metadata and controls
89 lines (79 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { AndroidTriplet } from "react-native-node-api-modules";
import { isNinjaAvailable } from "./ninja.js";
function getCmakeGenerator() {
if (isNinjaAvailable()) {
return "Ninja";
} else {
return "Unix Makefiles";
}
}
export const DEFAULT_ANDROID_TRIPLETS = [
"aarch64-linux-android",
"armv7a-linux-androideabi",
"i686-linux-android",
"x86_64-linux-android",
] as const satisfies AndroidTriplet[];
type AndroidArchitecture = "armeabi-v7a" | "arm64-v8a" | "x86" | "x86_64";
export const ANDROID_ARCHITECTURES = {
"armv7a-linux-androideabi": "armeabi-v7a",
"aarch64-linux-android": "arm64-v8a",
"i686-linux-android": "x86",
"x86_64-linux-android": "x86_64",
} satisfies Record<AndroidTriplet, AndroidArchitecture>;
type AndroidConfigureOptions = {
triplet: AndroidTriplet;
ndkVersion: string;
};
export function getAndroidConfigureCmakeArgs({
triplet,
ndkVersion,
}: AndroidConfigureOptions) {
const { ANDROID_HOME } = process.env;
assert(typeof ANDROID_HOME === "string", "Missing env variable ANDROID_HOME");
assert(
fs.existsSync(ANDROID_HOME),
`Expected the Android SDK at ${ANDROID_HOME}`
);
const installNdkCommand = `sdkmanager --install "ndk;${ndkVersion}"`;
const ndkPath = path.resolve(ANDROID_HOME, "ndk", ndkVersion);
assert(
fs.existsSync(ndkPath),
`Missing Android NDK v${ndkVersion} (at ${ndkPath}) - run: ${installNdkCommand}`
);
const toolchainPath = path.join(
ndkPath,
"build/cmake/android.toolchain.cmake"
);
const architecture = ANDROID_ARCHITECTURES[triplet];
return [
"-G",
getCmakeGenerator(),
"--toolchain",
toolchainPath,
"-D",
"CMAKE_SYSTEM_NAME=Android",
// "-D",
// `CPACK_SYSTEM_NAME=Android-${architecture}`,
// "-D",
// `CMAKE_INSTALL_PREFIX=${installPath}`,
// "-D",
// `CMAKE_BUILD_TYPE=${configuration}`,
// "-D",
// "CMAKE_C_COMPILER_LAUNCHER=ccache",
// "-D",
// "CMAKE_CXX_COMPILER_LAUNCHER=ccache",
"-D",
`ANDROID_NDK=${ndkPath}`,
"-D",
`ANDROID_ABI=${architecture}`,
"-D",
"ANDROID_TOOLCHAIN=clang",
// "-D",
// `ANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL}`,
"-D",
"ANDROID_STL=c++_shared",
];
}