@@ -49,6 +49,34 @@ function getBuildPath(baseBuildPath: string, triplet: Triplet) {
4949 return path . join ( baseBuildPath , triplet ) ;
5050}
5151
52+ function getNdkPath ( ndkVersion : string ) {
53+ const { ANDROID_HOME } = process . env ;
54+ assert ( typeof ANDROID_HOME === "string" , "Missing env variable ANDROID_HOME" ) ;
55+ assert (
56+ fs . existsSync ( ANDROID_HOME ) ,
57+ `Expected the Android SDK at ${ ANDROID_HOME } ` ,
58+ ) ;
59+ const installNdkCommand = `sdkmanager --install "ndk;${ ndkVersion } "` ;
60+ const ndkPath = path . resolve ( ANDROID_HOME , "ndk" , ndkVersion ) ;
61+ assert (
62+ fs . existsSync ( ndkPath ) ,
63+ `Missing Android NDK v${ ndkVersion } (at ${ ndkPath } ) - run: ${ installNdkCommand } ` ,
64+ ) ;
65+ return ndkPath ;
66+ }
67+
68+ function getNdkToolchainPath ( ndkPath : string ) {
69+ const toolchainPath = path . join (
70+ ndkPath ,
71+ "build/cmake/android.toolchain.cmake" ,
72+ ) ;
73+ assert (
74+ fs . existsSync ( toolchainPath ) ,
75+ `No CMake toolchain found in ${ toolchainPath } ` ,
76+ ) ;
77+ return toolchainPath ;
78+ }
79+
5280export const platform : Platform < Triplet [ ] , AndroidOpts > = {
5381 id : "android" ,
5482 name : "Android" ,
@@ -85,26 +113,8 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
85113 cmakeJs,
86114 } ,
87115 ) {
88- const { ANDROID_HOME } = process . env ;
89- assert (
90- typeof ANDROID_HOME === "string" ,
91- "Missing env variable ANDROID_HOME" ,
92- ) ;
93- assert (
94- fs . existsSync ( ANDROID_HOME ) ,
95- `Expected the Android SDK at ${ ANDROID_HOME } ` ,
96- ) ;
97- const installNdkCommand = `sdkmanager --install "ndk;${ ndkVersion } "` ;
98- const ndkPath = path . resolve ( ANDROID_HOME , "ndk" , ndkVersion ) ;
99- assert (
100- fs . existsSync ( ndkPath ) ,
101- `Missing Android NDK v${ ndkVersion } (at ${ ndkPath } ) - run: ${ installNdkCommand } ` ,
102- ) ;
103-
104- const toolchainPath = path . join (
105- ndkPath ,
106- "build/cmake/android.toolchain.cmake" ,
107- ) ;
116+ const ndkPath = getNdkPath ( ndkVersion ) ;
117+ const toolchainPath = getNdkToolchainPath ( ndkPath ) ;
108118
109119 const commonDefinitions = [
110120 ...define ,
0 commit comments