default adb path
Summary: As I was setting up a new mac I had to change this setting in flipper settings. From a few android people that I've spoken to no one could answer me if the old one is still used. Ideally we should infer this during the first time flipper starts - `/opt/android_sdk` current default - `$HOME/Library/Android/sdk` adb from Android Studio - `$HOME/fbsource/third-party/toolchains/android-sdk` adb that is always available in fbsource Reviewed By: lblasa Differential Revision: D51120929 fbshipit-source-id: edb2a58b9c9f37465ea2fc5493975dd427d5523b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b08e6feb44
commit
e5f6ad0ca6
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
import fs from 'fs-extra';
|
||||||
import {resolve} from 'path';
|
import {resolve} from 'path';
|
||||||
import {Settings, Tristate} from 'flipper-common';
|
import {Settings, Tristate} from 'flipper-common';
|
||||||
import {readFile, writeFile, pathExists, mkdirp} from 'fs-extra';
|
import {readFile, writeFile, pathExists, mkdirp} from 'fs-extra';
|
||||||
@@ -18,7 +19,7 @@ export async function loadSettings(
|
|||||||
): Promise<Settings> {
|
): Promise<Settings> {
|
||||||
if (settingsString !== '') {
|
if (settingsString !== '') {
|
||||||
try {
|
try {
|
||||||
return replaceDefaultSettings(JSON.parse(settingsString));
|
return await replaceDefaultSettings(JSON.parse(settingsString));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error("couldn't read the user settingsString");
|
throw new Error("couldn't read the user settingsString");
|
||||||
}
|
}
|
||||||
@@ -48,9 +49,9 @@ function getSettingsFile() {
|
|||||||
|
|
||||||
export const DEFAULT_ANDROID_SDK_PATH = getDefaultAndroidSdkPath();
|
export const DEFAULT_ANDROID_SDK_PATH = getDefaultAndroidSdkPath();
|
||||||
|
|
||||||
function getDefaultSettings(): Settings {
|
async function getDefaultSettings(): Promise<Settings> {
|
||||||
return {
|
return {
|
||||||
androidHome: getDefaultAndroidSdkPath(),
|
androidHome: await getDefaultAndroidSdkPath(),
|
||||||
enableAndroid: true,
|
enableAndroid: true,
|
||||||
enableIOS: os.platform() === 'darwin',
|
enableIOS: os.platform() === 'darwin',
|
||||||
enablePhysicalIOS: os.platform() === 'darwin',
|
enablePhysicalIOS: os.platform() === 'darwin',
|
||||||
@@ -69,14 +70,24 @@ function getDefaultSettings(): Settings {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultAndroidSdkPath() {
|
async function getDefaultAndroidSdkPath() {
|
||||||
return os.platform() === 'win32' ? getWindowsSdkPath() : '/opt/android_sdk';
|
if (os.platform() === 'win32') {
|
||||||
|
return `${os.homedir()}\\AppData\\Local\\android\\sdk`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// non windows platforms
|
||||||
|
|
||||||
|
// created when created a project in Android Studio
|
||||||
|
const androidStudioSdkPath = `${os.homedir()}/Library/Android/sdk`;
|
||||||
|
if (await fs.exists(androidStudioSdkPath)) {
|
||||||
|
return androidStudioSdkPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '/opt/android_sdk';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWindowsSdkPath() {
|
async function replaceDefaultSettings(
|
||||||
return `${os.homedir()}\\AppData\\Local\\android\\sdk`;
|
userSettings: Partial<Settings>,
|
||||||
}
|
): Promise<Settings> {
|
||||||
|
return {...(await getDefaultSettings()), ...userSettings};
|
||||||
function replaceDefaultSettings(userSettings: Partial<Settings>): Settings {
|
|
||||||
return {...getDefaultSettings(), ...userSettings};
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user