Ubuntu 19.10无Android Studio配置Flutter:sdkmanager路径错误求助
Hey mateo, I’ve been in your exact situation before—setting up Flutter without Android Studio can be tricky with those path variables, but let’s get this sorted out step by step.
The Problem with Your Current Setup
You mentioned you set ANDROID_SDK_HOME and ANDROID_HOME to the direct path of sdkmanager, but that’s not right. These environment variables need to point to the root directory of your Android SDK, not the specific tool binary. That’s why Flutter still can’t find the sdkmanager tool.
Step 1: Correct Your Environment Variables
First, let’s update your shell configuration file (most likely ~/.bashrc for Ubuntu 19.10):
- Open the file in a text editor:
nano ~/.bashrc - Scroll to the bottom and add these lines (based on your description, your SDK root directory is
/home/mateo/toolssince your cmdline-tools are nested inside it):# Android SDK Configuration export ANDROID_SDK_ROOT=/home/mateo/tools export ANDROID_HOME=$ANDROID_SDK_ROOT # For backward compatibility with older tools export PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/platform-toolsANDROID_SDK_ROOTis the official recommended variable now, pointing to your SDK’s root folder.- Adding
cmdline-tools/latest/bintoPATHlets your system (and Flutter) find thesdkmanagertool directly. - Including
platform-toolsensures you can useadband other essential tools later.
Step 2: Apply the Changes
Save the file (press Ctrl+O, then Enter in nano) and exit (Ctrl+X). Then run this command to make the changes take effect immediately:
source ~/.bashrc
If you use zsh instead of bash, replace .bashrc with .zshrc in both steps.
Step 3: Verify the Fix
- First, check if
sdkmanageris now accessible:
If this prints a version number, your path is set correctly.sdkmanager --version - Next, run Flutter’s diagnostic tool to confirm it recognizes the SDK:
You should no longer see the error about missing sdkmanager. If Flutter asks you to install additional components (like platform tools or build tools), you can useflutter doctorsdkmanagerto install them directly, e.g.:sdkmanager "platform-tools" "build-tools;33.0.2"
Quick Note on SDK Structure
Double-check that your SDK folder structure looks like this:
/home/mateo/tools/ ├── cmdline-tools/ │ └── latest/ │ ├── bin/ │ │ └── sdkmanager │ └── ... (other cmdline-tool files) └── (future folders like platform-tools, build-tools will go here)
If your cmdline-tools isn’t inside a latest subfolder, you might need to rename it—Flutter expects this structure to locate the tools correctly.
内容的提问来源于stack exchange,提问作者mateomotriz

