I have a Ubuntu Xenial VM running in OpenStack, there I've downloaded the latest Android SDK tools ( tools_r25.2.3-linux.zip ) from https://developer.android.com/studio/index.html. And everything is well configured:
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ANDROID_HOME=<ANDROID_SDK_PATH>
PATH=${PATH}:${ANDROID_HOME}
echo "sdk.dir=<ANDROID_SDK_PATH>" > <MY_ANDROID_PROJECT_PATH>/local.properties
But when try to execute task: ./gradlew clean
, error occurs:
Preparing "Install Android SDK Build-Tools 25".
Warning: Trying to install into ${ANDROID_HOME}/build-tools/25.0.0/ but package "Android SDK Tools 25.2.4" already exists at ${ANDROID_HOME}. It must be deleted or moved away before installing into a child directory.
Preparing "Install Android SDK Platform 25".
Warning: Trying to install into ${ANDROID_HOME}/platforms/android-25/ but package "Android SDK Tools 25.2.4" already exists at ${ANDROID_HOME}. It must be deleted or moved away before installing into a child directory.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':demo'.
> Failed to install the following SDK components:
[Android SDK Build-Tools 25, Android SDK Platform 25]
Please install the missing components using the SDK manager in Android Studio.
And actually as the error log mentions, I have the required tools installed. Run $ANDROID_HOME/bin/sdkmanager --list
shows my installed packages:
Installed packages:
Path | Version | Description | Location
------- | ------- | ------- | -------
build-tools;25.0.0 | 25.0.0 | Android SDK Build-Tools 25 | build-tools/25.0.0/
extras;android;m2repository | 41.0.0 | Android Support Repository, re... | extras/android/m2repository/
platform-tools | 25.0.2 | Android SDK Platform-Tools 25.0.2 | platform-tools/
platforms;android-25 | 3 | Android SDK Platform 25, rev 3 | platforms/android-25/
tools | 25.2.4 | Android SDK Tools 25.2.4 | tools/
What could be wrong here? I'm a bit suspicious of the SDK path here.
Just confirmed my speculation - this is due to the new change made in the latest Android SDK release.
Thanks god we have a time machine, so that we can go back to see what exactly happened (can't really find any cue from SDK Tools Release Notes).
Let's have a look at the file structures of ANDROID_HOME
before and after the change.
Before:
android-sdk-linux
├── SDK Readme.txt
├── add-ons (empty)
├── platforms (empty)
└── tools
├── a bunch of preloaded tools
├── ...
└── ...
After:
tools
├── a bunch of preloaded tools
├── ...
└── ...
No more add-ons
or platforms
, only the tools
as the new root directory.
Problem: Gradle will be confused if you set the $ANDROID_HOME
directly to the unzipped top-most tools
directory.
Solution: After unzip the new SDK file (you'll get a tools
directory), create another directory (e.g. android-sdk
), and move the tools
directory completely inside the empty android-sdk
, then set environment variables as:
ANDROID_HOME=/android-sdk
PATH=${PATH}:${ANDROID_HOME}/tools
In short: DON'T set $ANDROID_HOME
directly to the new tools
parent directory, wrap it inside another parent!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With