android_sdk_setup
Configure Android SDK environment for development by checking, installing, or setting up required components like platform-tools and build-tools.
Instructions
Setup Android SDK and configure environment for Android development
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | No | Action to perform | check |
| components | No | SDK components to install (platform-tools, build-tools, platforms, etc.) |
Implementation Reference
- src/tools/setup-tools.ts:491-573 (handler)The handler function implementing the core logic for the 'android_sdk_setup' tool. It handles 'check', 'install', and 'configure' actions by detecting Android SDK paths, checking for sdkmanager, and installing specified components.handler: async (args: any) => { const homeDir = os.homedir(); const platform = process.platform; const androidPath = platform === 'darwin' ? path.join(homeDir, 'Library', 'Android', 'sdk') : platform === 'win32' ? path.join(homeDir, 'AppData', 'Local', 'Android', 'Sdk') : path.join(homeDir, 'Android', 'Sdk'); const results = { platform, androidPath, status: {} as any, installation: null as any, configuration: null as any }; // Check current status if (args.action === 'check' || args.action === 'install') { try { await fs.access(androidPath); results.status.sdkFound = true; // Check for sdkmanager const sdkManagerPaths = [ path.join(androidPath, 'cmdline-tools', 'latest', 'bin', 'sdkmanager'), path.join(androidPath, 'cmdline-tools', '17.0', 'bin', 'sdkmanager'), path.join(androidPath, 'tools', 'bin', 'sdkmanager') ]; let sdkManagerPath = null; for (const path of sdkManagerPaths) { try { await fs.access(path); sdkManagerPath = path; break; } catch (e) { // Continue checking } } results.status.sdkManager = sdkManagerPath; if (sdkManagerPath && args.action === 'install') { // Install requested components results.installation = { components: args.components || [], results: [] }; for (const component of args.components || []) { try { await processExecutor.execute(sdkManagerPath, [ '--install', component, '--sdk_root=' + androidPath ], { timeout: 300000 }); results.installation.results.push({ component, status: 'success' }); } catch (error) { results.installation.results.push({ component, status: 'failed', error: error instanceof Error ? error.message : String(error) }); } } } } catch (e) { results.status.sdkFound = false; results.status.message = 'Android SDK not found. Install Android Studio or command-line tools.'; } } return { success: true, data: results }; }
- src/tools/setup-tools.ts:472-489 (schema)The input schema (using Zod-like structure) defining the parameters for the android_sdk_setup tool: action and optional components array.inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['check', 'install', 'configure'], description: 'Action to perform', default: 'check' }, components: { type: 'array', items: { type: 'string' }, description: 'SDK components to install (platform-tools, build-tools, platforms, etc.)', default: ['platform-tools', 'build-tools;34.0.0', 'platforms;android-34'] } }
- src/tools/setup-tools.ts:469-574 (registration)The registration of the 'android_sdk_setup' tool within the createSetupTools function, including name, description, schema, and handler.tools.set('android_sdk_setup', { name: 'android_sdk_setup', description: 'Setup Android SDK and configure environment for Android development', inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['check', 'install', 'configure'], description: 'Action to perform', default: 'check' }, components: { type: 'array', items: { type: 'string' }, description: 'SDK components to install (platform-tools, build-tools, platforms, etc.)', default: ['platform-tools', 'build-tools;34.0.0', 'platforms;android-34'] } } }, handler: async (args: any) => { const homeDir = os.homedir(); const platform = process.platform; const androidPath = platform === 'darwin' ? path.join(homeDir, 'Library', 'Android', 'sdk') : platform === 'win32' ? path.join(homeDir, 'AppData', 'Local', 'Android', 'Sdk') : path.join(homeDir, 'Android', 'Sdk'); const results = { platform, androidPath, status: {} as any, installation: null as any, configuration: null as any }; // Check current status if (args.action === 'check' || args.action === 'install') { try { await fs.access(androidPath); results.status.sdkFound = true; // Check for sdkmanager const sdkManagerPaths = [ path.join(androidPath, 'cmdline-tools', 'latest', 'bin', 'sdkmanager'), path.join(androidPath, 'cmdline-tools', '17.0', 'bin', 'sdkmanager'), path.join(androidPath, 'tools', 'bin', 'sdkmanager') ]; let sdkManagerPath = null; for (const path of sdkManagerPaths) { try { await fs.access(path); sdkManagerPath = path; break; } catch (e) { // Continue checking } } results.status.sdkManager = sdkManagerPath; if (sdkManagerPath && args.action === 'install') { // Install requested components results.installation = { components: args.components || [], results: [] }; for (const component of args.components || []) { try { await processExecutor.execute(sdkManagerPath, [ '--install', component, '--sdk_root=' + androidPath ], { timeout: 300000 }); results.installation.results.push({ component, status: 'success' }); } catch (error) { results.installation.results.push({ component, status: 'failed', error: error instanceof Error ? error.message : String(error) }); } } } } catch (e) { results.status.sdkFound = false; results.status.message = 'Android SDK not found. Install Android Studio or command-line tools.'; } } return { success: true, data: results }; } });
- src/utils/tool-categories.ts:396-404 (helper)Tool categorization entry for 'android_sdk_setup' in the TOOL_REGISTRY, defining its category, platform, requirements, and performance expectations.'android_sdk_setup': { name: 'android_sdk_setup', category: ToolCategory.ESSENTIAL, platform: 'android', requiredTools: [], description: 'Setup Android SDK and configure environment for Android development', safeForTesting: true, performance: { expectedDuration: 5000, timeout: 600000 } }