Error: Failed to find target with hash string 'android-28'

走远了吗. 提交于 2020-05-13 04:18:43

问题


When I sync my project in build.gradle(Project: Allo) I see this error

Failed to find target with hash string 'android-28'in: C:\Users\hacker\AppData\Local\Android\Sdk

Config:

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


回答1:


Read Set Up the Android P SDK.

android {
compileSdkVersion 'android-P'

defaultConfig {
    targetSdkVersion 'P'
}

For the best development experience with the Android P Preview SDK, we recommend that you install the latest Android Studio 3.2 canary.

You should install the Android P Preview SDK as follows:

  • Click Tools > SDK Manager.

  • In the SDK Platforms tab, select Android P Preview.

  • In the SDK Tools tab, select Android SDK Build-Tools 28-rc2 (or higher).

  • Click OK to begin install.




回答2:


I got the error "Failed to find target with hash string 'android-28'", None of the solutions above solved my issue.

Here's what caused my problem:

in the project gradle.build I added a user defined extension key value as such:

ext {
    ANDROID_COMPILE_SDK_VERSION=28
}

Then in the module gradle.build I then referenced this value as such:

android {
   compileSdkVersion rootProject.ext.ANDROID_COMPILE_SDK_VERSION
   ...

That's what causes the error!! What I did to correct the issue was to code it this way:

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

In other words, compileSdkVerion wants an interger, not a string. The same it true with minSdkVerion, targetSdkVersion and versionCode in your gradle script.

I don't know if that's the problem that the above posters were experiencing, but that at least one way in which that error message can occur. And by the way, I could use support libraries 28.0.0




回答3:


Replace these two dependencies

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

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

with these

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

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



来源:https://stackoverflow.com/questions/50420428/error-failed-to-find-target-with-hash-string-android-28

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