如何找到问题 Android SDK 3.0 错误:(9,5)错误:未找到资源 android:attr/colorError

8
当我进行make操作时,遇到了以下错误信息:Error:(9, 5) error: resource android:attr/colorError not found。如何找到此错误的问题所在呢?奇怪的是我有两个build.gradle文件:下面是我的build.gradle(Project:Projectname)文件:
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'

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

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

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

这是我的 build.gradle (Module:app) 文件:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 22
    defaultConfig {
        applicationId "org.acme.nfcedit"
        minSdkVersion 22
        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'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    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'
}

这个文件位于/home/users/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.1.0.aar/c41e5bc4d98504dc222d4eca88ab6d1b/res/values-v26/values-v26.xml,包含了内容。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Base.Theme.AppCompat" parent="Base.V26.Theme.AppCompat"/>
    <style name="Base.Theme.AppCompat.Light" parent="Base.V26.Theme.AppCompat.Light"/>
    <style name="Base.V26.Theme.AppCompat" parent="Base.V26.Theme.AppCompat">
        <!-- We can use the platform styles on API 26+ -->
        <item name="colorError">?android:attr/colorError</item>
    </style>
    <style name="Base.V26.Theme.AppCompat.Light" parent="Base.V23.Theme.AppCompat.Light">
        <!-- We can use the platform styles on API 26+ -->
        <item name="colorError">?android:attr/colorError</item>
    </style>
    <style name="Base.V26.Widget.AppCompat.Toolbar" parent="Base.V7.Widget.AppCompat.Toolbar">
        <item name="android:touchscreenBlocksFocus">true</item>
        <item name="android:keyboardNavigationCluster">true</item>
    </style>
    <style name="Base.Widget.AppCompat.Toolbar" parent="Base.V26.Widget.AppCompat.Toolbar"/>
</resources>

我不知道?android:attr/colorError是什么意思。

谢谢。


展示你的 build.gradle 文件。 - IntelliJ Amiya
我展示了它,这是我的第一个文件。实际上,我有两个build.gradle文件:一个是我的(项目:Edit)(见上文),另一个是我的(模块:app)。 - dubis
展示你的 build.gradle (module : app) 文件。 - Muhammad Hannan
嘿@dubis,你解决了吗?我也遇到了同样的问题 :/. - Abushawish
我将所有源代码复制到文本文件中,并创建了一个新项目。我使用新的build.gradle编译出了一个APK。 - dubis
尝试使用以下公式计算工作日数:=NETWORKDAYS(TO_DATE(A2); TO_DATE(B2)) * (E2-D2) - IF(INDEX(SPLIT(A2; " "); 1; 2) > D2; D2 - INDEX(SPLIT(A2,;" "); 1; 2); ) - IF(INDEX(SPLIT(B2; " "); 1; 2) < E2; E2 - INDEX(SPLIT(B2; " "); 1; 2); )。很抱歉,我无法在该网站上回复。 - player0
3个回答

24

属性名为"android:attr/colorError"被appcompat库在API 26及以上版本中引用。但是该构建正在使用sdk版本22进行编译。

因此,在您的应用程序模块的build.gradle文件中,将compileSdkVersion增加到26,以使其与您正在使用的appcompat库的版本一致。

换句话说,现在你有:

compileSdkVersion 22
implementation 'com.android.support:appcompat-v7:26.1.0'

但是,这两个版本应该是一致的。因此,请看以下内容会发生什么:

compileSdkVersion 26
implementation 'com.android.support:appcompat-v7:26.1.0'

如果你想在22版本编译,将appcompat改为22似乎不起作用。 - Stephen M -on strike-
嗨兄弟,我的项目在26中,但我的主分支只有24。那我该怎么办? - marlonpya
如果您可以在主分支中将compileSdkVersion设置为26,那么我相信android:attr/colorError将可供使用。如果这不可能实现,那么我建议尝试将appcompat库版本降至24。 - albert c braun

1
compileSdkVersion 22更改为compileSdkVersion 26

0

这里有一个针对 RN>0.60 的更新。在 android\build.gradle 中,在 allprojects 块内放置以下内容,以确保子项目具有更新的 compileSdkVersion。

subprojects {
    afterEvaluate {
        project ->
            if (project.hasProperty("android")) {
                android {
                    compileSdkVersion = 28
                    buildToolsVersion = "28.0.3"
                }
            }
    }
}

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