Android Studio 无法编译值文件

问题描述 投票:0回答:2

在 Android Studio 中构建应用程序时,出现“无法编译值文件”错误。回溯起来,发现原因是这样的:

> Task :app:mergeDebugResources /home/******/.gradle/caches/transforms-3/2b32a52804d1f1842c2b39552e0635b5/transformed/material-1.5.0/res/values/values.xml:203:4: Invalid <color> for given resource value.

当我在values.xml文件中找到有错误的行时,它是这样的:

<bool name="mtrl_btn_textappearance_all_caps">true</bool>

在研究此错误时,我尝试了“清理项目”、“重建项目”、“使用 --scan 运行”、修复任何警告,并根据建议的修复调整 gradle.build 中的compileAndroidSkd 级别,但没有建议的解决方案解决了该问题错误。

我知道无法编辑values.xml 文件中的值,因为它是Android Studio 的一部分,而不是我的应用程序。所以,我想知道这个错误可能有什么解决方案。另外,我想知道是否可以在应用程序内覆盖values.xml中的值,以便不更改原始.xml文件,以供将来参考?

这是我的 gradle.build 代码:

Plugins {
id 'com.android.application'

}

安卓{ 编译SDK 31

defaultConfig {
    applicationId "com.******.******"
    minSdk 21
    targetSdk 31
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

}

依赖项{

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

}

android-studio sdk android-gradle-plugin
2个回答
0
投票

当我遇到“无法编译值文件”错误时,结果发现我错误地将颜色定义为 红色 当它应该是 @颜色/红色

我没有收到编辑的投诉,F2也没有发现任何东西。我刚刚复习了每一行,直到让我震惊为止。


0
投票

这个错误发生在我身上 升级 android studio giraffe 到 Iguana 和 升级 AGP(Android Gradle 插件)并花了我一天的时间来解决:(

我做过的事:

1-此代码

<bool name="mtrl_btn_textappearance_all_caps">true</bool>
属于Material dependency,我将其从xml.values中删除,然后得到了与上面一行代码相同的错误,并且...... ==>这不是关于材料版本或xml.values行代码,实际上它与“app:mergeDebugResources”相关所以studio在读取资源(xml.values)时遇到问题

2-我删除了“

C:\Users\UserName\.gradle\caches
”中的所有内容,但没有帮助。

3-做了很多“清理项目”、“重建项目”、“使用 --scan 运行”、无效缓存并在每个解决方案后重新启动,但没有帮助

我的解决方案:==>我只在1个项目中遇到这个错误(其他项目在Iguana Upadte之后都正常),所以我检查了

C:\Users\UserName\AndroidStudioProjects\Myproject\.gradle
&有3个名为8.0、8.4、8.7的文件夹,它们是AGP版本 。 我删除了 8.4 & 8.7 & 并做了(清理、重建、无效缓存重新启动)并解决了问题!

P.S:我想我多次升级AGP版本导致错误。 还要检查 build.gradle(Module) 中的 Kotlin 版本,这应该是最新版本。

© www.soinside.com 2019 - 2024. All rights reserved.