Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated android home variable + doc #1772

Merged
merged 7 commits into from May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/common/projectVersionHelper.ts
Expand Up @@ -36,6 +36,18 @@ export const REACT_NATIVE_PACKAGES: Record<string, ParsedPackage> = {
},
};

export function RNPackageVersionsToPackageVersion(
packageVersions: RNPackageVersions,
): PackageVersion[] {
const res: PackageVersion[] = [];
Object.keys(packageVersions).forEach(key => {
const item: PackageVersion = {};
item[key] = packageVersions[key];
res.push(item);
});
return res;
}

export class ProjectVersionHelper {
private static SEMVER_INVALID = "SemverInvalid";

Expand Down
16 changes: 13 additions & 3 deletions src/extension/commands/testDevEnvironment.ts
Expand Up @@ -3,7 +3,11 @@

import { ErrorHelper } from "../../common/error/errorHelper";
import { InternalErrorCode } from "../../common/error/internalErrorCode";
import { ProjectVersionHelper, REACT_NATIVE_PACKAGES } from "../../common/projectVersionHelper";
import {
ProjectVersionHelper,
REACT_NATIVE_PACKAGES,
RNPackageVersionsToPackageVersion,
} from "../../common/projectVersionHelper";
import { AppLauncher } from "../appLauncher";
import { RNProjectObserver } from "../rnProjectObserver";
import { runChecks } from "../services/validationService/checker";
Expand Down Expand Up @@ -59,7 +63,13 @@ export class TestDevEnvironment extends Command {
[ValidationCategoryE.macOS]:
(projectObserver && projectObserver.isRNMacosProject) || false,
} as const;

await runChecks(shouldCheck);
if (project && projectObserver) {
await runChecks(
shouldCheck,
RNPackageVersionsToPackageVersion(projectObserver.rnPackageVersions),
);
} else {
await runChecks(shouldCheck);
}
}
}
6 changes: 6 additions & 0 deletions src/extension/rnProjectObserver.ts
Expand Up @@ -14,6 +14,7 @@ export class RNProjectObserver {
private _isRNAndroidHermesProject: boolean;
private _isRNIosHermesProject: boolean;
private _isRNHermesProject: boolean;
private _rnPackageVersions: RNPackageVersions;

constructor(projectRoot: string, rnPackageVersions: RNPackageVersions) {
this._isRNMacosProject = false;
Expand All @@ -23,6 +24,7 @@ export class RNProjectObserver {
this._isRNAndroidHermesProject = false;
this._isRNIosHermesProject = false;
this._isRNHermesProject = false;
this._rnPackageVersions = rnPackageVersions;

this.initialize(projectRoot, rnPackageVersions);
}
Expand Down Expand Up @@ -72,6 +74,10 @@ export class RNProjectObserver {
return this._isRNAndroidHermesProject;
}

public get rnPackageVersions(): RNPackageVersions {
return this._rnPackageVersions;
}

public get isRNIosHermesProject(): boolean {
return this._isRNIosHermesProject;
}
Expand Down
7 changes: 5 additions & 2 deletions src/extension/services/validationService/checker.ts
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as nls from "vscode-nls";
import { PackageVersion } from "../../../common/projectVersionHelper";
import { OutputChannelLogger } from "../../log/OutputChannelLogger";
import { getChecks } from "./checks";
import { ValidationCategoryE, IValidation, ValidationResultT } from "./checks/types";
Expand Down Expand Up @@ -54,6 +55,7 @@ const statusToSymbol = {

export const runChecks = async (
options_?: Partial<Record<ValidationCategoryE, boolean>>,
versions?: PackageVersion[],
): Promise<void> => {
const options = Object.assign(
{
Expand All @@ -66,8 +68,9 @@ export const runChecks = async (

outputChannel.setFocusOnLogChannel();
outputChannel.info(toLocale("DevEnvVerificationStart", "Starting Environment check..."));

const checks = await evaluteChecks(getChecks().filter(it => options?.[it.category] === true));
const checks = await evaluteChecks(
getChecks(versions).filter(it => options?.[it.category] === true),
);

let outStr = `<<< ${toLocale(
"DevEnvVerificationHeader",
Expand Down
10 changes: 4 additions & 6 deletions src/extension/services/validationService/checks/env.ts
Expand Up @@ -17,10 +17,9 @@ const toLocale = nls.loadMessageBundle();
const convertPathWithVars = (str: string) =>
str.replace(/%([^%]+)%/g, (_, n) => process.env[n] || _);

async function test(): Promise<ValidationResultT> {
const envVars = {
ANDROID_HOME: process.env.ANDROID_HOME,
};
async function test(androidHomeVariableName: string = "ANDROID_HOME"): Promise<ValidationResultT> {
const envVars: Record<string, string | undefined> = {};
envVars[androidHomeVariableName] = process.env[androidHomeVariableName];

const resolvedEnv = fromEntries(
Object.entries(envVars).map(([key, val]) => [
Expand All @@ -43,7 +42,6 @@ async function test(): Promise<ValidationResultT> {
const notFoundPath = Object.entries(resolvedEnv).find(
([, val]) => val.resolved && !fs.existsSync(val.resolved),
)?.[0];

if (notFoundPath) {
return {
status: "failure",
Expand All @@ -68,7 +66,7 @@ async function test(): Promise<ValidationResultT> {
}

const androidHome: IValidation = {
label: "ANDROID_HOME Env",
label: "Android Env",
description: toLocale(
"AndroidHomeEnvCheckDescription",
"Required for launching React Native apps",
Expand Down
20 changes: 17 additions & 3 deletions src/extension/services/validationService/checks/index.ts
Expand Up @@ -5,7 +5,9 @@
// https://www.npmjs.com/package/envinfo // does not list all required info
// https://www.npmjs.com/package/command-exists // might find its use later on

import * as semver from "semver";
import { PromiseUtil } from "../../../../common/node/promise";
import { PackageVersion } from "../../../../common/projectVersionHelper";
import { adbAndroid, adbExpo } from "./adb";
import cocoaPods from "./cocoaPods";
import emulator from "./emulator";
Expand All @@ -28,10 +30,10 @@ import macos from "./macos";

import { IValidation } from "./types";

export const getChecks = (): IValidation[] => {
export const getChecks = (versions: PackageVersion[] = []): IValidation[] => {
// if some checks become obsolete (e.g. no need to check both npm and yarn) - write logic here

const checks = [
const checks: IValidation[] = [
iosDeploy,
adbAndroid,
adbExpo,
Expand All @@ -53,7 +55,19 @@ export const getChecks = (): IValidation[] => {
macos,
xcodeBuild,
xcodeBuildVersionRNmacOS,
] as const;
];

const rnVersionContainer = versions.find(it => Object.keys(it).includes("reactNativeVersion"));
if (
rnVersionContainer &&
semver.gte(rnVersionContainer.reactNativeVersion, "0.68.0") &&
["linux", "darwin"].includes(process.platform)
) {
const androidEnvCheck = checks.find(it => it.label === "Android Env");
if (androidEnvCheck) {
androidEnvCheck.exec = androidEnvCheck.exec.bind(null, "ANDROID_SDK_ROOT");
}
}

checks.forEach(it => {
it.exec = PromiseUtil.promiseCacheDecorator(it.exec);
Expand Down
1 change: 1 addition & 0 deletions test/extension/checkEnvironment.test.ts
Expand Up @@ -103,6 +103,7 @@ suite("checkEnvironment", function () {

const envVars = {
ANDROID_HOME: process.env.ANDROID_HOME,
ANDROID_SDK_ROOT: process.env.ANDROID_SDK_ROOT,
};

const setEnv = (arg: string) => {
Expand Down
3 changes: 2 additions & 1 deletion test/smoke/docs/run-locally.md
Expand Up @@ -63,6 +63,7 @@ Add these lines to `~/.zshrc` (create one if it doesn't exist):
export ANDROID_SDK_ROOT=$ANDROID_HOME
PATH="$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools/bin"
```
> Notice: since 0.68 version of React Native ```ANDROID_HOME``` has to be changed to ```ANDROID_SDK_ROOT``` for linux and macOS
* **Linux**:
Add these lines to `~/.bash_profile` (create one if it doesn't exist):
```bash
Expand All @@ -71,7 +72,7 @@ Add these lines to `~/.bash_profile` (create one if it doesn't exist):
export ANDROID_SDK_ROOT=$ANDROID_HOME
PATH="$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools/bin"
```
> Notice: it's important to add $ANDROID_HOME/emulator before other paths because otherwise emulator will refuse to start from any directory but sdk ones.
> Notice: it's important to add $ANDROID_HOME/emulator before other paths because otherwise emulator will refuse to start from any directory but sdk ones
1. (**Linux** only) Install **KVM** on your system and **reboot** your system.
```bash
sudo apt install qemu-kvm
Expand Down