无法使用哈希字符串android-23找到目标

Al *_*ath 93 android gradle android-build

当尝试从git://github.com/osmdroid/osmdroid构建OpenStreetMapView时,我收到此错误:

failed to find target with hash string android-23: D:\Users\myusername\AppData\Local\Android
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?以前类似的问题建议检查android 23是否未安装,但在我的情况下,确实如此.

以下是一些相关信息:

ANDROID_HOME是 D:\Users\myusername\AppData\Local\Android\sdk

D:\Users\myusername\AppData\Local\Android\sdk\platforms\ 包含目录\ android-23 \,(以及android-19,android-21,android-22,android-MNC)

的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "org.osmdroid.example"
        minSdkVersion 8
        targetSdkVersion 23
        versionCode 16
        versionName "4.4-SNAPSHOT"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'

    }
    lintOptions {
        abortOnError false
    }
}


dependencies {
    compile 'android.support:compatibility-v4:23+'
    compile project(':osmdroid-android')
    //compile 'org.osmdroid:osmdroid-third-party:4.4-SNAPSHOT'
}
Run Code Online (Sandbox Code Playgroud)

我尝试将targetSdkVersion和compileSdkVersion更改为22.这会导致错误消息更改为"android-22"而不是"android-23".

SDK Manager: 在此输入图像描述

hta*_*oya 77

在我的情况下,清除caché不起作用.

在SDK Manager上,请务必选中"显示包描述"框; 那么您还应该为您愿意安装的版本选择"Google API".

安装它然后你应该没问题

  • 这很有效.在SDK管理器完成后必须下载构建工具,但绝对不需要执行delete .gradle文件夹或invalidate缓存. (2认同)

Moh*_*Ali 23

在Android Studio中File -> Invalidate Caches/Restart为我解决了这个问题.


Al *_*ath 17

这个问题的答案.

Gradle不时变得愚蠢,擦除缓存是我找到的唯一解决方案.你会在你的用户主文件夹下找到一个隐藏的.gradle文件夹,而另一个文件夹是osmdroid的结帐位置.

  • 我删除了文件夹,重新启动,它仍然有问题 (3认同)

Rad*_*ion 14

我通过打开Android SDK Manager并为所有23.xx版本安装构建工具来解决这个问题.

查看截图.

在此输入图像描述


Sag*_*tel 6

注意:我认为这可能是Android Studio中的错误.

  1. 转到项目结构
  2. 选择App Module
  3. 在第一个"属性"选项卡下,将Compile SDK版本从Google API xx更改为API XX(例如,API 23而不是Google API 23)
  4. 按确定
  5. 等待正在进行的过程完成,在我的情况下,我此时没有收到错误.

现在将Compiled Sdk Version还原为Google API xx.

如果这不起作用,那么:

  1. 使用Google API(Google API xx而不是API xx),降低构建工具版本(例如Google API 23和构建工具版本23.0.1)
  2. 按确定并等待正在进行的过程完成
  3. 将构建工具版本恢复为更改之前的版本
  4. 按确定
  5. 等待完成流程.
  6. 完成!