Skip to content

Commit

Permalink
Fix issues while passing APK path to install subcommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Dec 6, 2024
1 parent 39e0ebc commit 7aef1a2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/commands/android/subcommands/install/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ADB from '../../utils/appium-adb';
import {getBinaryLocation} from '../../utils/common';
import {execBinaryAsync} from '../../utils/sdk';
import {showMissingBinaryHelp} from '../common';
import untildify from 'untildify';

export async function installApp(options: Options, sdkRoot: string, platform: Platform): Promise<boolean> {
try {
Expand Down Expand Up @@ -63,7 +64,7 @@ export async function installApp(options: Options, sdkRoot: string, platform: Pl

Logger.log();

options.path = path.resolve(process.cwd(), options.path as string);
options.path = path.resolve(process.cwd(), untildify(options.path as string));
if (!existsSync(options.path)) {
Logger.log(`${colors.red('No APK file found at: ' + options.path)}\nPlease provide a valid path to the APK file.\n`);

Expand All @@ -72,7 +73,7 @@ export async function installApp(options: Options, sdkRoot: string, platform: Pl

Logger.log('Installing APK...');

const installationStatus = await execBinaryAsync(adbLocation, 'adb', platform, `-s ${options.deviceId} install ${options.path}`);
const installationStatus = await execBinaryAsync(adbLocation, 'adb', platform, `-s ${options.deviceId} install "${options.path}"`);
if (installationStatus?.includes('Success')) {
Logger.log(colors.green('APK installed successfully!\n'));

Expand All @@ -93,7 +94,7 @@ const handleError = (consoleOutput: any) => {
Logger.log(colors.red('\nError while installing APK:'));

let errorMessage = consoleOutput;
if (consoleOutput.includes('INSTALL_FAILED_ALREADY_EXISTS')) {
if (consoleOutput.includes('INSTALL_FAILED_ALREADY_EXISTS') || consoleOutput.includes('INSTALL_FAILED_VERSION_DOWNGRADE')) {
errorMessage = 'APK with the same package name already exists on the device.\n';
errorMessage += colors.reset('\nPlease uninstall the app first from the device and then install again.\n');
errorMessage += colors.reset(`To uninstall, use: ${colors.cyan('npx @nightwatch/mobile-helper android uninstall --app')}\n`);
Expand Down

0 comments on commit 7aef1a2

Please sign in to comment.