You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过Chocolatey安装Android SDK组件?解决手动下载缺失问题

Hey there, let's sort out that missing Android SDK components problem once and for all! Android Studio's GUI can be hit-or-miss with downloads sometimes, so using the command-line sdkmanager tool is usually the most reliable way to track down and install the build tools, platforms, and other bits you're missing.

1. First, Find Your sdkmanager Tool

First off, you need to locate where sdkmanager lives. It's part of the Command Line Tools package, which you might already have installed via Android Studio:

  • On Windows: Check %ANDROID_SDK_ROOT%\cmdline-tools\latest\bin (if you haven't set ANDROID_SDK_ROOT, it's usually C:\Users\<YourUsername>\AppData\Local\Android\Sdk)
  • On macOS/Linux: Look in $ANDROID_SDK_ROOT/cmdline-tools/latest/bin (default path is ~/Library/Android/sdk on macOS, ~/Android/Sdk on Linux)

If you don't see the cmdline-tools folder, open Android Studio, go to Tools > SDK Manager > SDK Tools, check Android SDK Command-line Tools (latest), and click Apply to install it first.

2. List All Available & Installed Components

Before installing, let's confirm exactly what's missing. Run this command to see a full list of components (installed ones will be marked):

sdkmanager --list

To narrow it down to the bits you care about, filter the output:

  • Windows: sdkmanager --list | findstr "build-tools platform"
  • macOS/Linux: sdkmanager --list | grep "build-tools\|platform"

This will show you which build tool versions and Android platform SDKs are available or already installed.

3. Install the Missing Components

Now let's install what you need—here are common commands for key components:

Build Tools

Install a specific version (replace 34.0.0 with the version you need):

sdkmanager "build-tools;34.0.0"

Or install the latest available version:

sdkmanager "build-tools;latest"

Android Platform SDKs

Install the SDK for a specific Android version (replace android-34 with your target API level):

sdkmanager "platforms;android-34"

Other Essential Components

Don't forget these often-overlooked bits that are critical for building and testing:

sdkmanager "platform-tools" "emulator" "extras;android;m2repository" "extras;google;m2repository"

Batch Install Multiple Components

You can combine multiple components into one command to save time:

sdkmanager "build-tools;34.0.0" "platforms;android-34" "platform-tools" "emulator"
4. Fix Common Installation Hiccups
  • Permission Errors (macOS/Linux): If you get a "permission denied" message, run the command with sudo:
    sudo ./sdkmanager "build-tools;34.0.0"
    
  • Network/Proxy Issues: If you're behind a firewall or proxy, specify your proxy settings when running commands:
    sdkmanager --list --proxy=http --proxy_host=your-proxy-address --proxy_port=your-proxy-port
    
  • Corrupted Downloads: If a component fails to install, delete its folder from the SDK directory (e.g., build-tools/34.0.0) and re-run the install command.
5. Sync with Android Studio

After installing via the command line, open Android Studio and do a quick sync to make sure the IDE recognizes the new components:

  1. Go to File > Sync Project with Gradle Files
  2. Or, open Tools > SDK Manager—you should see the newly installed components marked as installed now.

That should cover all the bases for getting your missing SDK components set up properly!

内容的提问来源于stack exchange,提问作者T. Samuel

火山引擎 最新活动