【问题标题】:How to find issue Android SDK 3.0 Error:(9, 5) error: resource android:attr/colorError not found如何查找问题 Android SDK 3.0 Error:(9, 5) error: resource android:attr/colorError not found
【发布时间】:2017-11-02 17:55:03
【问题描述】:

当我进行制作时如何找到此错误的问题我收到此错误消息: Error:(9, 5) error: resource android:attr/colorError not found

奇怪的是我有 2 个 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
  • 我向它展示了这是我的第一个文件。事实上,我有 2 个 build.gradle 文件:一个是我的(Projet:Edit)(见上文),一个是我的(模块:app)
  • 显示你的build.gradle (module : app )
  • 嘿@dubis 你让它工作了吗?有同样的问题:/.
  • 我复制了文本文件中的所有源代码,并做了一个新项目。我可以用新的 build.gradle 编译一个 APK。

标签: android android-layout android-studio


【解决方案1】:

名为“android:attr/colorError”的属性由 API 26 及更高版本的 appcompat 库引用。但是构建是使用 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 似乎不起作用。
  • 嗨,兄弟,我的项目在 26 号,但我的主分支必须到 24 号.. 那怎么办?
  • 如果你可以在你的 master 分支中将 compileSdkVersion 设置为 26,那么我相信 android:attr/colorError 将可以使用。如果这不可能,那么我建议尝试将 appcompat 库版本降低到 24。
【解决方案2】:

compileSdkVersion 22 更改为compileSdkVersion 26

【讨论】:

    【解决方案3】:

    这是 RN>0.60 的更新。在您的 android\build.gradle 中,将以下内容放在 allprojects 块中,以确保子项目具有更新的 compileSdkVersion。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-07
      • 1970-01-01
      • 1970-01-01
      • 2015-11-26
      • 2011-02-20
      • 2014-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多