Java Android资源编译失败

Java Android资源编译失败,java,android,gradle,aapt,Java,Android,Gradle,Aapt,我正在开发一个android应用程序,我需要设计支持库,因此当我在build.gradle(应用程序)中添加implementation'com.android.support:design:27.1.1'时,出现以下错误: 原因:org.gradle.internal.UncheckedException:java.util.concurrent.ExecutionException:com.android.builder.internal.aapt.v2.Aapt2Exception:and

我正在开发一个android应用程序,我需要设计支持库,因此当我在build.gradle(应用程序)中添加
implementation'com.android.support:design:27.1.1'
时,出现以下错误:

原因: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.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
}
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'
}
我的应用程序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
}
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'
}

注意:我已经清理并重新构建了项目,并且我还使缓存无效并清除了缓存

您使用的库之一似乎与支持库具有相同的名称属性。我建议你开始从浓缩咖啡中排除它们,然后看看你是否可以修复它,并持续将其设置到其他库中,直到找到哪个库使用了它

androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

通过研究,我发现MenuView(工具栏中的菜单)定义了这个属性

<declare-styleable name="MenuView">
    ...
    <!-- Default background for each menu item. -->
    <attr name="itemBackground" format="color|reference" />
    ...
</declare-styleable>

...
...
我使用了
而不是
来解决此问题


请升级到版本1.4.1。

在我的情况下出现错误,因为对于生成错误的视图, xml命名空间定义过多 ,即:
xmlns:android=”http://schemas.android.com/apk/res/android“

这意味着我们需要删除xmlns,因为在已编译的xml中,它出现在三个地方


因此,删除
xmlns:android=”http://schemas.android.com/apk/res/android“
已解决此问题。

是否有itemBackground属性?请尝试升级gradle和SDK。@matio我已向工具栏和按钮添加了一些背景属性,但与itemBackground不同attribute@grrigore我已经更新了一切,但是,当我添加设计库时,它显示了相同的错误。您是否尝试过使缓存无效并重新启动?谢谢,这是由于pinview库造成的,所以如果我想同时使用pinview库和设计库,该怎么办。@mdadil2019也为您的pinview实现执行此操作,如果无效,则您可以始终在其github页面上发布问题,我试着查看他们github页面上的问题,但没有类似的问题。@AalapPatel好的,我已经报告了问题ok,但是如果您已将此标记为答案,那么还有问题吗???