installApp
Install APK files on Android devices for mobile app testing and automation workflows.
Instructions
Install an APK file on the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apkPath | Yes | Path to the APK file to install |
Implementation Reference
- src/server/appTools.ts:80-92 (handler)The registered tool handler for 'installApp'. It instantiates the InstallApp class and calls its execute method with the provided APK path, handling errors and formatting the response.const installAppHandler = async (device: BootedDevice, args: InstallAppArgs) => { try { const installApp = new InstallApp(device); const result = await installApp.execute(args.apkPath); return createJSONToolResponse({ message: `Installed app from ${args.apkPath}`, ...result }); } catch (error) { throw new ActionableError(`Failed to install app: ${error}`); } };
- Core logic for installing the APK: resolves path, extracts package name using aapt dump, checks if already installed, installs with adb install -r, determines success and if it was an upgrade.async execute(apkPath: string): Promise<{ success: boolean; upgrade: boolean }> { if (!path.isAbsolute(apkPath)) { apkPath = path.resolve(process.cwd(), apkPath); } // Extract package name from APK const packageNameCmd = `dump badging "${apkPath}" | grep "package:" | grep -o "name='[^']*'" | cut -d= -f2 | tr -d "'"`; const packageName = await this.adb.executeCommand(packageNameCmd); // Check if app is already installed const isInstalledCmd = `shell pm list packages -f ${packageName.trim()} | grep -c ${packageName.trim()}`; const isInstalledOutput = await this.adb.executeCommand(isInstalledCmd, undefined, undefined, true); const isInstalled = parseInt(isInstalledOutput.trim(), 10) > 0; const installOutput = await this.adb.executeCommand(`install -r "${apkPath}"`); const success = installOutput.includes("Success"); return { success: success, upgrade: isInstalled && success }; }
- src/server/appTools.ts:20-22 (schema)Zod input schema for the installApp tool, validating the apkPath parameter.export const installAppSchema = z.object({ apkPath: z.string().describe("Path to the APK file to install"), });
- src/server/appTools.ts:109-114 (registration)Registers the installApp tool with the ToolRegistry using the name, description, input schema, and handler function.ToolRegistry.registerDeviceAware( "installApp", "Install an APK file on the device", installAppSchema, installAppHandler );