When developing Android or Ionic apps inside WSL (Windows Subsystem for Linux), you might hit this frustrating error:
[ERROR] Error while getting native targets for android: No valid Android SDK root found.
This usually happens when running:
npm run dev:android
ionic cap run android
ionic cordova run android
Don’t worry — it’s a common issue when working across Windows and WSL.
Here’s what causes it and how to fix it cleanly.
Why This Happens
There are two main culprits behind this error:
1. WSL Can’t See the Android SDK
Your Android SDK is installed on Windows, not inside WSL.
Typically, it lives here:
C:\Users\<Your-Username>\AppData\Local\Android\Sdk
In WSL, that same folder appears under:
/mnt/c/Users/<Your-Username>/AppData/Local/Android/Sdk
However, if your Windows username contains a space (like FIRST NAME), Linux treats it as two separate paths unless you quote it properly.
That’s why the Android build tools inside WSL can’t find your SDK.
2. Missing Android Command-Line Tools
Even if the SDK path is correct, you might still lack the essential Android tools (sdkmanager, avdmanager, etc.) that WSL needs to manage devices and builds.
Without these, the SDK can’t be validated — hence the “no valid SDK root” message.
Step-by-Step Fix
Follow these steps in your WSL terminal 👇
1. Set Correct Android SDK Paths
Run these commands (replace your username if needed):
echo 'export ANDROID_HOME="/mnt/c/Users/Ernest Kabahima/AppData/Local/Android/Sdk"' >> ~/.bashrc
echo 'export ANDROID_SDK_ROOT="$ANDROID_HOME"' >> ~/.bashrc
echo 'export PATH="$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin"' >> ~/.bashrc
source ~/.bashrc
Confirm the path:
echo $ANDROID_HOME
You should see:
/mnt/c/Users/Ernest Kabahima/AppData/Local/Android/Sdk
2. Install Android Command-Line Tools
If sdkmanager isn’t recognized, install it with:
sudo apt update
sudo apt install google-android-cmdline-tools-11.0-installer -y
This installs the latest command-line tools inside /usr/lib/android-sdk/.
3. Link WSL Tools to Your Windows SDK
Make sure your Windows SDK has the proper structure:
mkdir -p "/mnt/c/Users/Ernest Kabahima/AppData/Local/Android/Sdk/cmdline-tools/latest"
sudo ln -s /usr/lib/android-sdk/cmdline-tools/* "/mnt/c/Users/Ernest Kabahima/AppData/Local/Android/Sdk/cmdline-tools/latest/"
Now WSL and Windows share the same SDK tools.
4. Accept SDK Licenses
This ensures the tools can run properly:
yes | sdkmanager --licenses
5. Verify Your Setup
Check versions and SDK content:
adb version
sdkmanager --list | head -20
If both work, your SDK is ready.
6. Run Your Project Again
Now re-run your dev command:
npm run dev:android
If you still get a native-run error, use:
npm run dev:android -- --no-native-run
That tells the system to fall back to Cordova’s runner.
Quick Recap
| Problem | Cause | Fix |
|---|---|---|
| No valid Android SDK root | WSL can’t find Windows SDK | Use quoted path /mnt/c/...
|
| sdkmanager not found | Missing SDK tools | sudo apt install google-android-cmdline-tools-11.0-installer |
| native-run errors | Emulator or device not found | Start emulator or use --no-native-run
|
Bonus Tip: Avoid Spaces in SDK Paths
If possible, move your Android SDK to a path without spaces, such as:
C:\Android\Sdk
Then update your environment variables accordingly.
This avoids quoting issues entirely and makes WSL integration smoother.
Conclusion
This issue boils down to two things:
- WSL not interpreting Windows paths with spaces
- Missing command-line tools for Android builds
By setting your environment variables properly and installing the SDK tools, you can run and build Android apps inside WSL just like a native Linux environment — no more “No valid Android SDK root” headaches.
Top comments (0)