android_sdk_setup
Configure Android SDK and development environment by checking, installing, or setting up required components for Android app development.
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' actions: checks SDK presence, locates sdkmanager, and installs specified components using sdkmanager.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-490 (schema)JSON schema defining the input parameters for the android_sdk_setup tool, including action (check/install/configure) and 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:468-574 (registration)Registration of the android_sdk_setup tool in the createSetupTools function's tools Map, including name, description, inputSchema, and handler.// Android SDK Setup Tool 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 }; } });