> Failed to find target with hash string 'android-26' in: /opt/android-sdk-linux

不问归期 提交于 2019-12-19 10:36:09

问题


  • 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:


  1. remove all previous android sdk files from /opt/
  2. cd /opt && wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
  3. unzip sdk-tools-linux-3859397.zip -d android-sdk-linux

  4. 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"
  1. source /etc/profile

check android home:

echo $ANDROID_HOME
  1. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!