ANDROID_SDK_ROOT support (#2106)
Summary: According to Google, ANDROID_HOME is deprecated. This means, that having only ANDROID_SDK_ROOT as environment variable leading to Android SDK is enough. Flipper supports only ANDROID_HOME, so I would like to add ANDROID_SDK_ROOT support. However, there is a set of rules of ANDROID_HOME and ANDROID_SDK_ROOT priority. Everything is mentioned on a this page: https://developer.android.com/studio/command-line/variables ## Changelog Added ANDROID_SDK_ROOT environment variable support Pull Request resolved: https://github.com/facebook/flipper/pull/2106 Test Plan: Probably I would need a help with this Reviewed By: mweststrate Differential Revision: D27505024 Pulled By: passy fbshipit-source-id: 8bdc66a9652c673fd44944d87af1efc9e93d0f1b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ebcb535fd3
commit
c9b6f6c7d9
@@ -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`,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,10 @@ export type Healthcheck = {
|
||||
run: (
|
||||
env: EnvironmentInfo,
|
||||
settings?: Settings,
|
||||
) => Promise<HealthchecRunResult>;
|
||||
) => Promise<HealthcheckRunResult>;
|
||||
};
|
||||
|
||||
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<HealthchecRunResult> {
|
||||
): Promise<HealthcheckRunResult> {
|
||||
try {
|
||||
const output = await promisify(exec)(command);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user