( env: NodeJS.ProcessEnv = process.env, )
| 39 | } |
| 40 | |
| 41 | export async function ensureAndroidSdkPathConfigured( |
| 42 | env: NodeJS.ProcessEnv = process.env, |
| 43 | ): Promise<void> { |
| 44 | const existingDirs: string[] = []; |
| 45 | let detectedRoot: string | undefined; |
| 46 | |
| 47 | for (const sdkRoot of resolveAndroidSdkRoots(env)) { |
| 48 | const presentDirs: string[] = []; |
| 49 | for (const relativeDir of ANDROID_SDK_BIN_DIRS) { |
| 50 | const candidate = path.join(sdkRoot, relativeDir); |
| 51 | if (await pathExists(candidate)) { |
| 52 | presentDirs.push(candidate); |
| 53 | } |
| 54 | } |
| 55 | if (presentDirs.length === 0) continue; |
| 56 | if (!detectedRoot) { |
| 57 | detectedRoot = sdkRoot; |
| 58 | } |
| 59 | existingDirs.push(...presentDirs); |
| 60 | } |
| 61 | |
| 62 | if (detectedRoot) { |
| 63 | env.ANDROID_SDK_ROOT = env.ANDROID_SDK_ROOT?.trim() || detectedRoot; |
| 64 | env.ANDROID_HOME = env.ANDROID_HOME?.trim() || detectedRoot; |
| 65 | } |
| 66 | |
| 67 | if (existingDirs.length === 0) return; |
| 68 | |
| 69 | const currentEntries = (env.PATH ?? '') |
| 70 | .split(path.delimiter) |
| 71 | .map((entry) => entry.trim()) |
| 72 | .filter((entry) => entry.length > 0); |
| 73 | env.PATH = uniqueNonEmpty([...existingDirs, ...currentEntries]).join(path.delimiter); |
| 74 | } |
no test coverage detected