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 = () => {
|
const watchAndroidDevices = () => {
|
||||||
// get emulators
|
// get emulators
|
||||||
promisify(which)('emulator')
|
promisify(which)('emulator')
|
||||||
.catch(() => `${process.env.ANDROID_HOME || ''}/tools/emulator`)
|
.catch(
|
||||||
|
() =>
|
||||||
|
`${
|
||||||
|
process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || ''
|
||||||
|
}/tools/emulator`,
|
||||||
|
)
|
||||||
.then((emulatorPath) => {
|
.then((emulatorPath) => {
|
||||||
child_process.exec(
|
child_process.exec(
|
||||||
`${emulatorPath} -list-avds`,
|
`${emulatorPath} -list-avds`,
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ function setProcessState(store: Store) {
|
|||||||
const androidHome = settings.androidHome;
|
const androidHome = settings.androidHome;
|
||||||
const idbPath = settings.idbPath;
|
const idbPath = settings.idbPath;
|
||||||
|
|
||||||
if (!process.env.ANDROID_HOME) {
|
if (!process.env.ANDROID_HOME && !process.env.ANDROID_SDK_ROOT) {
|
||||||
process.env.ANDROID_HOME = androidHome;
|
process.env.ANDROID_HOME = androidHome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ export type Healthcheck = {
|
|||||||
run: (
|
run: (
|
||||||
env: EnvironmentInfo,
|
env: EnvironmentInfo,
|
||||||
settings?: Settings,
|
settings?: Settings,
|
||||||
) => Promise<HealthchecRunResult>;
|
) => Promise<HealthcheckRunResult>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type HealthchecRunResult = {
|
export type HealthcheckRunResult = {
|
||||||
hasProblem: boolean;
|
hasProblem: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
};
|
};
|
||||||
@@ -114,26 +114,65 @@ export function getHealthchecks(): Healthchecks {
|
|||||||
label: 'SDK Installed',
|
label: 'SDK Installed',
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
run: async (_: EnvironmentInfo) => {
|
run: async (_: EnvironmentInfo) => {
|
||||||
if (process.env.ANDROID_HOME) {
|
|
||||||
const androidHome = process.env.ANDROID_HOME;
|
const androidHome = process.env.ANDROID_HOME;
|
||||||
if (!fs.existsSync(androidHome)) {
|
const androidSdkRoot = process.env.ANDROID_SDK_ROOT;
|
||||||
return {
|
|
||||||
|
let androidHomeResult: HealthcheckRunResult;
|
||||||
|
if (!androidHome) {
|
||||||
|
androidHomeResult = {
|
||||||
hasProblem: true,
|
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.`,
|
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');
|
const platformToolsDir = path.join(androidHome, 'platform-tools');
|
||||||
if (!fs.existsSync(path.join(androidHome, 'platform-tools'))) {
|
if (!fs.existsSync(platformToolsDir)) {
|
||||||
return {
|
androidHomeResult = {
|
||||||
hasProblem: true,
|
hasProblem: true,
|
||||||
message: `Android SDK Platform Tools not found at the expected location "${platformToolsDir}". Probably they are not installed.`,
|
message: `Android SDK Platform Tools not found at the expected location "${platformToolsDir}". Probably they are not installed.`,
|
||||||
};
|
};
|
||||||
}
|
} else {
|
||||||
return await tryExecuteCommand(
|
androidHomeResult = await tryExecuteCommand(
|
||||||
`"${path.join(platformToolsDir, 'adb')}" version`,
|
`"${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(
|
async function tryExecuteCommand(
|
||||||
command: string,
|
command: string,
|
||||||
): Promise<HealthchecRunResult> {
|
): Promise<HealthcheckRunResult> {
|
||||||
try {
|
try {
|
||||||
const output = await promisify(exec)(command);
|
const output = await promisify(exec)(command);
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user