java - 安卓资源编译失败

标签 java android gradle aapt

我正在开发一个需要设计支持库的 android 应用程序,所以当我将 implementation 'com.android.support:design:27.1.1' 添加到我的 build.gradle(app ) 然后出现以下错误:

Caused by: org.gradle.internal.UncheckedException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed MyAppDirectory\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2489: error: duplicate value for resource 'attr/itemBackground' with config ''.

但是当我删除依赖项时 implementation 'com.android.support:design:27.1.1' 然后错误消失,gradle 构建成功。

我的项目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版本。

关于java - 安卓资源编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51709716/

相关文章:

android - 在android中比较两次

Gradle 对分发插件中的 distZip 任务不做任何处理

java - 拥有两个 Maven Web 模块时如何正确使用 log4j?

android - 我们可以在 android 中使用自动弹跳球吗

java - 如何在一个文档中解析多个连续的 xml 文件?

Android-将日期和文本保存到手机内存中的 SQLite?

hibernate - 构建/泊坞具有数据库连接的Spring Boot应用程序的最佳实践是什么?

java - 控制 gradle 插件中使用的第三方库的日志输出

java - 为什么 2 个不同 HashMap 的相同值的输出为 false?

java - 有没有更好的方法在 Matcher 中使用 group() 提取名称-值?