【问题标题】:Error: Failed to find target with hash string 'android-28'错误:找不到带有哈希字符串“android-28”的目标
【发布时间】:2018-05-18 23:32:26
【问题描述】:

当我在 build.gradle(Project: Allo) 中同步我的项目时,我看到了这个错误

在 C:\Users\hacker\AppData\Local\Android\Sdk 中找不到带有哈希字符串 'android-28' 的目标

配置:

apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.example.android.allo"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0 rc2'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation 'com.android.support:design:28.0.0 rc2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

【问题讨论】:

    标签: android android-studio synchronization


    【解决方案1】:

    阅读Set Up the Android P SDK

    android {
    compileSdkVersion 'android-P'
    
    defaultConfig {
        targetSdkVersion 'P'
    }
    

    为了获得最佳的 Android P Preview SDK 开发体验,我们 建议您安装最新的 Android Studio 3.2 canary。

    您应该按如下方式安装 Android P Preview SDK:

    • 点击工具> SDK 管理器

    • 在 SDK 平台选项卡中,选择 Android P 预览

    • 在 SDK 工具选项卡中,选择 Android SDK Build-Tools 28-rc2(或 更高)。

    • 单击“确定”开始安装。

    【讨论】:

    • @SamuelRobert 确实。
    • 谢谢,但是如何安装 android Studio 3.2 canary?
    • 我必须将 compileSdkVersion 设置为 'android-P' 并将 targetSdkVersion 设置为 28。
    【解决方案2】:

    我收到错误“无法找到带有哈希字符串'android-28'的目标”,上述解决方案都没有解决我的问题。

    这是导致我的问题的原因:

    在项目 gradle.build 中,我添加了一个用户定义的扩展键值:

    ext {
        ANDROID_COMPILE_SDK_VERSION=28
    }
    

    然后在模块 gradle.build 中我引用了这个值:

    android {
       compileSdkVersion rootProject.ext.ANDROID_COMPILE_SDK_VERSION
       ...
    

    这就是导致错误的原因!我为纠正这个问题所做的就是这样编码:

    android {
      compileSdkVersion Integer.valueOf(rootProject.ext.ANDROID_COMPILE_SDK_VERSION)
    

    换句话说,compileSdkVerion 需要一个整数,而不是字符串。 gradle 脚本中的 minSdkVerion、targetSdkVersion 和 versionCode 也是如此。

    我不知道这是否是上述发帖人遇到的问题,但至少有一种方式会出现该错误消息。顺便说一句,我可以使用支持库 28.0.0

    【讨论】:

      【解决方案3】:

      替换这两个依赖

      实现'com.android.support:appcompat-v7:28.0.0 rc2'

      实现'com.android.support:design:28.0.0 rc2'

      这些

      实现'com.android.support:design:28.0.0-rc01'

      实现'com.android.support:appcompat-v7:28.0.0-rc01'

      【讨论】:

        猜你喜欢
        • 2020-01-16
        • 1970-01-01
        • 2016-01-24
        • 1970-01-01
        • 1970-01-01
        • 2018-11-23
        • 1970-01-01
        • 2016-06-26
        • 2017-03-20
        相关资源
        最近更新 更多