错误:未能找到哈希字符串为“android-28”的目标。

6

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

无法在以下位置找到哈希字符串为'android-28'的目标: C:\Users\hacker\AppData\Local\Android\Sdk

配置信息:

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'
}

and this is the image

3个回答

9

阅读设置 Android P SDK

android {
compileSdkVersion 'android-P'

defaultConfig {
    targetSdkVersion 'P'
}

为了获得最佳的 Android P 预览版 SDK 开发体验,我们建议您安装最新的 Android Studio 3.2 canary 版本。您可以按照以下步骤安装 Android P 预览版 SDK:
1. 单击“工具 > SDK 管理器”。 2. 在 SDK 平台选项卡中,选择“Android P 预览版”。 3. 在 SDK 工具选项卡中,选择“Android SDK 构建工具 28-rc2”(或更高版本)。 4. 单击“确定”开始安装。

@SamuelRobert 确实。 - IntelliJ Amiya
谢谢,但我该如何安装Android Studio 3.2 Canary版本? - user9576863
我必须将compileSdkVersion设置为“android-P”,将targetSdkVersion设置为28。 - Edmund Johnson

4
我收到一个错误信息:“无法找到哈希字符串为'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。


0

替换这两个依赖项

implementation 'com.android.support:appcompat-v7:28.0.0 rc2'

implementation 'com.android.support:design:28.0.0 rc2'

使用以下依赖项替换

implementation 'com.android.support:design:28.0.0-rc01'

implementation 'com.android.support:appcompat-v7:28.0.0-rc01'


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接