Skip to main content
Glama

android_install_apk

Install APK files on Android devices or emulators by specifying device serial and file path. Supports app replacement and test APK installation.

Instructions

Install an APK file to an Android device or emulator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serialYesDevice serial number
apkPathYesPath to APK file
optionsNo

Implementation Reference

  • Executes APK installation on Android device using ADB. Validates input schema, checks APK file existence and extension, builds ADB install command with optional flags (-r for replace, -t for test), runs via processExecutor with 5min timeout, returns success with output or throws detailed errors.
    handler: async (args: any) => { const validation = AndroidAdbInstallSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { serial, apkPath, options = {} } = validation.data; // Validate APK path if (!apkPath.endsWith('.apk')) { throw new Error(`File must have .apk extension. Invalid path: ${apkPath}`); } // Check if APK file exists try { await fs.access(apkPath); } catch { throw new Error(`APK file not found: ${apkPath}`); } const adb_args = ['-s', serial, 'install']; if (options.replace) { adb_args.push('-r'); } if (options.test) { adb_args.push('-t'); } adb_args.push(apkPath); const result = await processExecutor.execute('adb', adb_args, { timeout: 300000, // 5 minutes timeout for APK installation }); if (result.exitCode !== 0) { throw new Error(`APK installation failed: ${result.stderr || result.stdout}`); } return { success: true, data: { serial, apkPath: path.basename(apkPath), output: result.stdout, }, }; }
  • Zod schema for validating android_install_apk inputs: required serial (device ID) and apkPath, optional options with replace and test booleans.
    const AndroidAdbInstallSchema = z.object({ serial: z.string().min(1), apkPath: z.string().min(1), options: z.object({ replace: z.boolean().optional(), test: z.boolean().optional(), }).optional(), });
  • Registers the android_install_apk tool in the tools Map within createAndroidTools factory function. Includes name, JSON inputSchema mirroring Zod schema, description, and references the handler function.
    tools.set('android_install_apk', { name: 'android_install_apk', description: 'Install an APK file to an Android device or emulator', inputSchema: { type: 'object', properties: { serial: { type: 'string', minLength: 1, description: 'Device serial number' }, apkPath: { type: 'string', minLength: 1, description: 'Path to APK file' }, options: { type: 'object', properties: { replace: { type: 'boolean', description: 'Replace existing app if installed' }, test: { type: 'boolean', description: 'Allow test APKs' } } } }, required: ['serial', 'apkPath'] }, handler: async (args: any) => { const validation = AndroidAdbInstallSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { serial, apkPath, options = {} } = validation.data; // Validate APK path if (!apkPath.endsWith('.apk')) { throw new Error(`File must have .apk extension. Invalid path: ${apkPath}`); } // Check if APK file exists try { await fs.access(apkPath); } catch { throw new Error(`APK file not found: ${apkPath}`); } const adb_args = ['-s', serial, 'install']; if (options.replace) { adb_args.push('-r'); } if (options.test) { adb_args.push('-t'); } adb_args.push(apkPath); const result = await processExecutor.execute('adb', adb_args, { timeout: 300000, // 5 minutes timeout for APK installation }); if (result.exitCode !== 0) { throw new Error(`APK installation failed: ${result.stderr || result.stdout}`); } return { success: true, data: { serial, apkPath: path.basename(apkPath), output: result.stdout, }, }; } });
  • Categorizes android_install_apk as ESSENTIAL Android tool requiring ADB, with performance expectations and testing safety info.
    'android_install_apk': { name: 'android_install_apk', category: ToolCategory.ESSENTIAL, platform: 'android', requiredTools: [RequiredTool.ADB], description: 'Install APK on Android device or emulator', safeForTesting: false, performance: { expectedDuration: 15000, timeout: 120000 } },

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/cristianoaredes/mcp-mobile-server'

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