Skip to main content
Glama

android_install_apk

Install APK files on Android devices or emulators by specifying device serial and APK path, with options to replace existing apps or allow test APKs.

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

  • Handler function that performs APK installation using ADB. Validates inputs, checks APK existence, constructs and executes adb install command with optional replace and test flags.
    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 input validation schema for the android_install_apk tool.
    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(), });
  • Registration of the android_install_apk tool within the createAndroidTools function, including name, description, inputSchema, and inline handler.
    // Android ADB - Install APK 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, }, }; } });

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