问题
- Ubuntu 16.04
- android-sdk at /opt/android-sdk-linux
- android home confugired (export ANDROID_HOME="/opt/android-sdk-linux/")
- there is no additional tools folder in /opt/android-sdk-linux/
my gradle file:
android {
compileSdkVersion 26
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "hu.prject.sandbox.sample"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
when run ./gradelew clean build
in the project folder, I got this output:
Starting a Gradle Daemon (subsequent builds will be faster) Preparing "Install Android SDK Build-Tools 21.1". "Install Android SDK Build-Tools 21.1" ready. Finishing "Install Android SDK Build-Tools 21.1" Installing Android SDK Build-Tools 21.1 in /opt/android-sdk-linux/build-tools/21.1.0 "Install Android SDK Build-Tools 21.1" complete. Preparing "Install Android SDK Platform 26". "Install Android SDK Platform 26" ready. Finishing "Install Android SDK Platform 26" Installing Android SDK Platform 26 in /opt/android-sdk-linux/platforms/android-26 "Install Android SDK Platform 26" complete.
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring project ':app'.
Failed to find target with hash string 'android-26' in: /opt/android-sdk-linux
IMPORTANT: in my case no android studio, no ui, only CLI
There is android-26 folder exist with content at /opt/android-sdk-linux/platforms/
回答1:
- remove all previous android sdk files from /opt/
cd /opt && wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
unzip sdk-tools-linux-3859397.zip -d android-sdk-linux
nano /etc/profile.d/android.sh
paste this lines:
export ANDROID_HOME="/opt/android-sdk-linux"
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH"
source /etc/profile
check android home:
echo $ANDROID_HOME
in /opt/android-sdk-linux
tools/bin/sdkmanager --update
tools/bin/sdkmanager "platforms;android-26" "build-tools;26.0.2" "extras;google;m2repository" "extras;android;m2repository"
tools/bin/sdkmanager --licenses
maybe enough at this point and the build will work...
but in my case missing some dependency, and check with
tools/bin/sdkmanager --list
update with the missing dependencies
tools/bin/sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.0-alpha9"
tools/bin/sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.0-alpha9"
after these build success
thanks for help NinjaCoder about build tool version
回答2:
Since your compileSDKVersion
is 26, use latest version of build tools.
buildToolsVersion "26.0.2"
来源:https://stackoverflow.com/questions/46896341/failed-to-find-target-with-hash-string-android-26-in-opt-android-sdk-linux