Android Studio Gradle构建失败-要求不存在的sdk版本

7
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说无法下载该软件包/不存在。 如何查找Android SDK 3.0错误:(9,5)错误:资源android:attr/colorError未找到 单击第一个提到的错误代码会打开一个名为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
}

3
为什么在依赖关系中永远不要使用加号,这就是原因。 - OneCricketeer
1
你也不需要一个JAR文件。compile group: 'joda-time', name: 'joda-time', version: '2.9.9' - OneCricketeer
2个回答

9

您在build.gradle中使用了带有+的design lib版本,这意味着它将下载最新版本。因此,请将其设置为26.1.0,然后它应该可以工作。支持库28处于alpha测试阶段,并在昨天发布了新的Android P预览版。


2

请确保在您的应用程序的build.gradle文件中包含以下内容:

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

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