java - Android资源编译失败
问题描述
我正在开发一个需要设计支持库的 android 应用程序,所以当我添加implementation 'com.android.support:design:27.1.1'
到我的 build.gradle(app) 时,会出现以下错误:
引起:org.gradle.internal.UncheckedException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android资源编译失败MyAppDirectory\app\build\intermediates\incremental\mergeDebugResources\merged .dir\values\values.xml:2489:错误:资源“attr/itemBackground”的重复值与配置“”。
但是当我删除依赖项时implementation 'com.android.support:design:27.1.1'
,错误就会消失并且 gradle build 成功。
我的项目 build.gradle
// 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.1.3'
classpath 'com.android.tools.build:gradle:3.3.0-alpha04'
// 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
}
我的应用程序 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "myapplicationid"
minSdkVersion 16
targetSdkVersion 27
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:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//third party libraries
implementation 'com.hbb20:ccp:2.2.2'
implementation 'info.hoang8f:fbutton:1.0.5'
implementation 'com.chaos.view:pinview:1.4.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
}
注意:我已经清理并重建了项目,并且我还使缓存失效并清除了
解决方案
通过一些研究,我发现MenuView(工具栏中的菜单)已经定义了这个属性。
<declare-styleable name="MenuView">
...
<!-- Default background for each menu item. -->
<attr name="itemBackground" format="color|reference" />
...
</declare-styleable>
我已经使用<attr name="android:itemBackground" />
而不是
<attr name="itemBackground" format="reference|color" />
解决此问题。
请升级到版本 1.4.1。
推荐阅读
- asp.net-mvc - 用户代码未处理空引用异常并且项目为空
- javascript - 选择选项后从下拉列表中选择 2 多选删除选项
- perl - wxPerl 和 PAR::Packer 以及缺少的依赖项
- python - 如何使用tkinter在函数内的另一个python文件中从其他python文件访问变量
- oauth-2.0 - 在微服务架构中我需要多少应用注册
- scrapy - Scrapy:如何获取分页链接?
- r - 如何使用 sparklyr 将宽数据框列转换为长格式?
- sql - 子查询返回超过 1 个值。解释将不胜感激
- javascript - 在 infotemplate 中显示属性表中的图像
- database - 检测和提取操作码序列