【问题标题】:Android Studio Gradle Build failing - asking for a sdk version that doesn't existAndroid Studio Gradle Build 失败 - 要求不存在的 sdk 版本
【发布时间】:2018-03-08 12:57:49
【问题描述】:

24 小时前,我的项目完美构建,没有错误。不更改任何代码,当我恢复工作时,它将不再构建。 现在检查旧的工作提交会产生相同的错误。

这些是我得到的错误代码:

Information:Gradle tasks [assemble]
Error:(9, 5) error: resource android:attr/dialogCornerRadius not found.
/home/liam/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0-alpha1.aar/536e4dd78846259cf8bef0fd6a3ea0e6/res/values/values.xml

我认为这是由于 Android P 的发布和我的 Android Studio 自动升级或类似的原因造成的。这可以解释为什么有效的旧提交会出现同样的错误。 这将是一个非常新的问题,这可以解释为什么我还找不到解决方案。

搜索这些错误代码会导致类似的问题,该问题已通过更改 gradle 构建文件中的 SDK 版本得到解决。我的问题与此不同,因为更改为 SDK 28(我很确定 28 甚至不存在)会导致 android studio 说这个包不可用/不存在可供下载。

How to find issue Android SDK 3.0 Error:(9, 5) error: resource android:attr/colorError not found

单击第一个提到的错误代码会导致打开一个名为 v28/values-v28.xml 的文件。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Base.Theme.AppCompat" parent="Base.V28.Theme.AppCompat"/>
    <style name="Base.Theme.AppCompat.Light" parent="Base.V28.Theme.AppCompat.Light"/>
    <style name="Base.V28.Theme.AppCompat" parent="Base.V26.Theme.AppCompat">
        <!-- We can use the platform styles on API 28+ -->
        <item name="dialogCornerRadius">?android:attr/dialogCornerRadius</item>
    </style>
    <style name="Base.V28.Theme.AppCompat.Light" parent="Base.V26.Theme.AppCompat.Light">
        <!-- We can use the platform styles on API 28+ -->
        <item name="dialogCornerRadius">?android:attr/dialogCornerRadius</item>
    </style>
</resources>

这是我的 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.timelord.timelord.timelord"
        minSdkVersion 24
        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'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:+'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation files('libs/joda-time-2.9.9.jar')
}

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

【问题讨论】:

  • 这就是为什么你从不在依赖项中使用加号的原因
  • 您也不需要 JAR 文件。 compile group: 'joda-time', name: 'joda-time', version: '2.9.9'

标签: android android-studio android-gradle-plugin


【解决方案1】:

您的 build.gradle 中有带 + 的设计库版本,这意味着它将下载最新版本。所以请将其设置为 26.1.0,它应该可以工作。支持 28 处于 alpha 阶段,昨天发布了新的 android P 预览版

【讨论】:

    【解决方案2】:

    确保在您的应用的 build.gradle 中有这些:

    dependencies {
       compile 'com.android.support:support-v13:27.+'
       compile 'com.android.support:design:27.+'
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-05
      • 1970-01-01
      • 2016-04-08
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 1970-01-01
      相关资源
      最近更新 更多