Skip to main content
Glama

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
NameRequiredDescriptionDefault
apkPathYesPath to the APK file to install

Implementation Reference

  • 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 }; }
  • 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"), });
  • 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 );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zillow/auto-mobile'

If you have feedback or need assistance with the MCP directory API, please join our Discord server