diff --git a/desktop/app/src/dispatcher/androidDevice.tsx b/desktop/app/src/dispatcher/androidDevice.tsx index 718aab77c..47e1a17aa 100644 --- a/desktop/app/src/dispatcher/androidDevice.tsx +++ b/desktop/app/src/dispatcher/androidDevice.tsx @@ -138,7 +138,12 @@ export default (store: Store, logger: Logger) => { const watchAndroidDevices = () => { // get emulators promisify(which)('emulator') - .catch(() => `${process.env.ANDROID_HOME || ''}/tools/emulator`) + .catch( + () => + `${ + process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || '' + }/tools/emulator`, + ) .then((emulatorPath) => { child_process.exec( `${emulatorPath} -list-avds`, diff --git a/desktop/app/src/init.tsx b/desktop/app/src/init.tsx index f94b402ed..d35ed7e6d 100644 --- a/desktop/app/src/init.tsx +++ b/desktop/app/src/init.tsx @@ -162,7 +162,7 @@ function setProcessState(store: Store) { const androidHome = settings.androidHome; const idbPath = settings.idbPath; - if (!process.env.ANDROID_HOME) { + if (!process.env.ANDROID_HOME && !process.env.ANDROID_SDK_ROOT) { process.env.ANDROID_HOME = androidHome; } diff --git a/desktop/doctor/src/index.ts b/desktop/doctor/src/index.ts index 03ff358ef..8c28808fb 100644 --- a/desktop/doctor/src/index.ts +++ b/desktop/doctor/src/index.ts @@ -46,10 +46,10 @@ export type Healthcheck = { run: ( env: EnvironmentInfo, settings?: Settings, - ) => Promise; + ) => Promise; }; -export type HealthchecRunResult = { +export type HealthcheckRunResult = { hasProblem: boolean; message: string; }; @@ -114,26 +114,65 @@ export function getHealthchecks(): Healthchecks { label: 'SDK Installed', isRequired: true, run: async (_: EnvironmentInfo) => { - if (process.env.ANDROID_HOME) { - const androidHome = process.env.ANDROID_HOME; - if (!fs.existsSync(androidHome)) { - return { - hasProblem: true, - message: `ANDROID_HOME points to a folder which does not exist: ${androidHome}. You can use Flipper Settings (File > Preferences) to point to a different location.`, - }; - } + const androidHome = process.env.ANDROID_HOME; + const androidSdkRoot = process.env.ANDROID_SDK_ROOT; + + let androidHomeResult: HealthcheckRunResult; + if (!androidHome) { + androidHomeResult = { + hasProblem: true, + message: `ANDROID_HOME is not defined. You can use Flipper Settings (File > Preferences) to point to its location.`, + }; + } else if (!fs.existsSync(androidHome)) { + androidHomeResult = { + hasProblem: true, + message: `ANDROID_HOME point to a folder which does not exist: ${androidHome}. You can use Flipper Settings (File > Preferences) to point to a different location.`, + }; + } else { const platformToolsDir = path.join(androidHome, 'platform-tools'); - if (!fs.existsSync(path.join(androidHome, 'platform-tools'))) { - return { + if (!fs.existsSync(platformToolsDir)) { + androidHomeResult = { hasProblem: true, message: `Android SDK Platform Tools not found at the expected location "${platformToolsDir}". Probably they are not installed.`, }; + } else { + androidHomeResult = await tryExecuteCommand( + `"${path.join(platformToolsDir, 'adb')}" version`, + ); } - return await tryExecuteCommand( - `"${path.join(platformToolsDir, 'adb')}" version`, - ); } - return await tryExecuteCommand('adb version'); + if (androidHomeResult.hasProblem == false) { + return androidHomeResult; + } + + let androidSdkRootResult: HealthcheckRunResult; + if (!androidSdkRoot) { + androidSdkRootResult = { + hasProblem: true, + message: `ANDROID_SDK_ROOT is not defined. You can use Flipper Settings (File > Preferences) to point to its location.`, + }; + } else if (!fs.existsSync(androidSdkRoot)) { + androidSdkRootResult = { + hasProblem: true, + message: `ANDROID_SDK_ROOT point to a folder which does not exist: ${androidSdkRoot}. You can use Flipper Settings (File > Preferences) to point to a different location.`, + }; + } else { + const platformToolsDir = path.join( + androidSdkRoot, + 'platform-tools', + ); + if (!fs.existsSync(platformToolsDir)) { + androidSdkRootResult = { + hasProblem: true, + message: `Android SDK Platform Tools not found at the expected location "${platformToolsDir}". Probably they are not installed.`, + }; + } else { + androidSdkRootResult = await tryExecuteCommand( + `"${path.join(platformToolsDir, 'adb')}" version`, + ); + } + } + return androidSdkRootResult; }, }, ], @@ -299,7 +338,7 @@ export async function runHealthchecks(): Promise< async function tryExecuteCommand( command: string, -): Promise { +): Promise { try { const output = await promisify(exec)(command); return {