-
-
Notifications
You must be signed in to change notification settings - Fork 197
Fix getting info for Android tools #2610
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
Conversation
Due to changes in Android SDK, we have to update the checks in CLI. While gathering system information, we check the android executable, which is no longer returning correct results. We use the android executable to find information about installed Android SDKs and to construct correct paths based on ANDROID_HOME. Fix this by listing directories inside ANDROID_HOME and find the information about installed SDKs from there. Fix messages pointing to `android` executable to point to `sdkmanager` (in case it exists). In order to fix this, we rely on the emulator executable, which is the real thing we need as it is the one that allows us to work with Android Emulators (this is changed in mobile-cli-lib). Fix sys-info checks and get correct path to emulator according to latest changes.
d8e2c83
to
54cff3a
Compare
lib/android-tools-info.ts
Outdated
@@ -186,6 +149,28 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { | |||
return null; | |||
} | |||
|
|||
private _cachedAndroidHomeValidationResult: boolean = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use @cache
decorator here instead of variable
lib/android-tools-info.ts
Outdated
@@ -318,44 +303,23 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { | |||
private async getInstalledTargets(): Promise<string[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method no longer needs to return Promise - its operations are sync now
As one of the methods in androidSysInfo no longer needs to be async, after removing its async signature, this lead to avalanche of methods that no longer needs to be async. So fix all of them.
344ceb7
to
95f3997
Compare
@@ -204,10 +203,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject | |||
} | |||
} | |||
|
|||
public async interpolateConfigurationFile(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void> { | |||
// TODO: Check if we can make this method sync. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method is already sync. Delete the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be exactly what we need to not depend on any particular tools sdk version. Well done!
@@ -186,6 +139,51 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { | |||
return null; | |||
} | |||
|
|||
@cache() | |||
public validateAndroidHomeEnvVariable(options?: { showWarningsAsErrors: boolean }): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need tests for this functionality? Will the cache work as expected here, don't we need to somehow include the "androidHome" to the cacheKey?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache decorator has tests here
The androidHome
will not be changed between executions of the method (I've also change androidHome to be only getter).
Regarding tests for the whole androidToolsInfo - we'll move it to nativescript-doctor
package very soon and we'll add tests there.
lib/android-tools-info.ts
Outdated
|
||
@cache() | ||
private getPathToSdkManagementTool(): string { | ||
const sdkmanagerName = "sdkmanager"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I understand the "sdkmanager" is lowercase, the variables containing "Sdkmanager" look little less readable to me. (sdkmanagerName, pahtToSdkmanager)
lib/android-tools-info.ts
Outdated
|
||
const isAndroidHomeValid = this.validateAndroidHomeEnvVariable(); | ||
|
||
if (isAndroidHomeValid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's not valid, we'll return "sdkmanager" as result. Shouldn't we throw an error in case the AndroidHome is invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is used just to get the path that we'll show in the additionalMessage
. The idea is that if something is not configured properly, tns doctor
command to show some suggestions how to fix the issue.
In case you execute any other command, CLI will fail immediately in case the ANDROID_HOME is not set. The default is sdkmanager
as when the ANDROID_HOME is not set, most probably the user does not have any Android SDK. After installing it, he'll have the new SDK, which requires usage of sdkmanager
not android
.
lib/android-tools-info.ts
Outdated
private async getAppCompatRange(): Promise<string> { | ||
let compileSdkVersion = await this.getCompileSdk(); | ||
private getAppCompatRange(): string { | ||
let compileSdkVersion = this.getCompileSdk(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not rename the "getCompileSdk()" method as "getCompileSdkVersion"? It returns a number and it's assigned to a variable sdkVersion, therefore I think it would be more correctly named this way
lib/android-tools-info.ts
Outdated
return _.findLast(AndroidToolsInfo.SUPPORTED_TARGETS.sort(), supportedTarget => _.includes(installedTargets, supportedTarget)); | ||
} | ||
|
||
private parseAndroidSdkString(androidSdkString: string): number { | ||
return parseInt(androidSdkString.replace(`${AndroidToolsInfo.ANDROID_TARGET_PREFIX}-`, "")); | ||
} | ||
|
||
private async getInstalledTargets(): Promise<string[]> { | ||
private getInstalledTargets(): string[] { | ||
if (!this.installedTargetsCache) { | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need this try/catch
. You can move the logger.trace in the if
instead of throw new Error
and do the rest in the else
.
The command `tns emulate android --available-devices` should list the available Android Virtual Devices on the current machine. It uses `android list avd` command which is no longer available. The alternative is to use the new `$ANDROID_HOME/tools/bin/avdmanager` executable or use the way we already have in the mobile-cli-lib - parse the `.ini` files of each device. Use the methods from `androidEmulatorServices` so the code will work with both old and new SDKs.
a286def
to
18b91a8
Compare
18b91a8
to
3dbd332
Compare
Due to changes in Android SDK, we have to update the checks in CLI. While gathering system information, we check the android executable, which is no longer returning correct results.
We use the android executable to find information about installed Android SDKs and to construct correct paths based on ANDROID_HOME. Fix this by listing directories inside ANDROID_HOME and find the information about installed SDKs from there.
Fix messages pointing to
android
executable to point tosdkmanager
(in case it exists).In order to fix this, we rely on the emulator executable, which is the real thing we need as it is the one that allows us to work with Android Emulators (this is changed in mobile-cli-lib).
Fix sys-info checks and get correct path to emulator according to latest changes.
PR in mobile-cli-lib telerik/mobile-cli-lib#906