【问题标题】:Android Studio: Error Code 1: Gradle: Execution failed for task ':app:processDebugResources'Android Studio:错误代码 1:Gradle:任务“:app:processDebugResources”执行失败
【发布时间】:2015-02-08 17:00:53
【问题描述】:

我要编译一个项目,我得到了Error:Gradle: Execution failed for task ':app:processDebugResources'.

这里是个例外:

错误:Gradle:任务“:app:processDebugResources”执行失败。 com.android.ide.common.internal.LoggedErrorException:无法运行命令:

D:\devtools\adt\sdk\build-tools\21.1.1\aapt.exe package -f --no-crunch -ID:\devtools\adt\sdk\platforms\android-21\android.jar -ME:\code\android\TVMediaPlayer\app\build\manifests\debug\AndroidManifest.xml -SE:\code\android\TVMediaPlayer\app\build\res\all\debug -AE:\code\android\TVMediaPlayer\ app\build\assets\debug -m -JE:\code\android\TVMediaPlayer\app\build\source\r\debug -FE:\code\android\TVMediaPlayer\app\build\libs\app-debug.ap_ - -debug-mode --custom-package com.skyworth.tvmediaplayer.app --output-text-symbols E:\code\android\TVMediaPlayer\app\build\symbols\debug

错误代码: 1

输出: E:\code\android\TVMediaPlayer\app\build\res\all\debug\drawable-hdpi-v4\ic_launcher.png:错误:重复文件。 E:\code\android\TVMediaPlayer\app\build\res\all\debug\drawable-hdpi\ic_launcher.png:原件在这里。版本限定符可能是隐含的。

这里是 gradle 文件:

    android {
        compileSdkVersion 21
        buildToolsVersion "21.0.2"

        defaultConfig {
            applicationId "com.jerrellmardis.amphitheatre"
            minSdkVersion 21
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
            renderscriptTargetApi 19

            buildConfigField "String", "TMDB_API_KEY", "\"${loadSecret("TMDB_API_KEY")}\""
        }
......
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:recyclerview-v7:21.0.0'
    compile 'com.android.support:leanback-v17:21.0.0'
    compile 'com.android.support:appcompat-v7:21.0.0'
    compile 'com.android.support:palette-v7:21.0.0'
    compile 'com.squareup.picasso:picasso:2.3.4'
    compile 'com.squareup.retrofit:retrofit:1.7.1'
    compile 'com.google.code.gson:gson:2.3'
    compile 'org.apache.commons:commons-lang3:3.3.2'
    compile 'org.apache.commons:commons-collections4:4.0'
    compile 'com.jakewharton:butterknife:6.0.0'
    compile 'com.github.satyan:sugar:1.3'
}

我对错误信息感到困惑,是我放错了 png 文件还是我的 gradle 配置文件有误?

【问题讨论】:

  • 尝试改成drawable-hdpi\ic_launcher.png:
  • 错误1基本上告诉你你有一个重复的文件...重命名或删除它。
  • @Sultan 非常感谢。我也发现了问题。这是因为我在 jar 文件中有重复的文件“ic_launcher.png”。
  • @KostasMatrix 非常感谢。我也发现了问题。这是因为我在 jar 文件中有重复的文件“ic_launcher.png”。

标签: java android android-studio android-gradle-plugin


【解决方案1】:

我在使用第三方库时遇到了同样的问题。

为了解决这个问题,我将 ic_launcher.png 文件从 drawable 文件夹移动到 mipmap 文件夹。问题解决了。

【讨论】:

  • 很奇怪。这为我解决了它,但我仍然很想知道为什么会发生这种情况......
【解决方案2】:
  • 如果您管理自己的 aar 文件:

您必须确保您的 gradle 和 buildToolsVersion 在您的项目和使用的 aars 中是相同的。

  • 如果您使用无法控制 gradle/build 版本的外部库:

联系作者或自行查看来源。一些库有未使用的启动器图标,这将导致此冲突。删除此图标将解决您的问题。在极少数情况下,相同名称的源(例如 menu.xml)也可能导致此问题。一个简单的解决方法是重命名您的资源。

【讨论】:

  • +1 用于重命名资源。不幸的是,如果多个第三方库都有自己的 ic_launcher 则不起作用。我最终手动导入了其中一些并删除了项目中的 ic_launcher,结果很不幸,但这是不可避免的。
  • 重命名资源解决了我的问题
【解决方案3】:

Simply RenameImage (Rightclick on the Image, Select Refactor and select Rename)。它将解决问题,因为library/Module 之一也在使用image with the same name

【讨论】:

    【解决方案4】:

    在 app.gradle 中添加aaptOptions.cruncherEnabled = false 解决了我的问题

    【讨论】:

    • 嗨。请在您的答案中添加更多信息。即这个问题背后的原因。
    【解决方案5】:

    如果其他人遇到此问题并且上述答案均未解决您的问题,您可以将此行添加到应用程序标记中的 AndroidManifest.xml 文件中:

    tools:replace="android:icon

    您还需要清单标记中的工具命名空间

    xmlns:tools="http://schemas.android.com/tools"

    所以它看起来像这样:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.example.sqlite" >`
    
       <application
            android:allowBackup="true"
            android:label="@string/app_name"
            android:theme="@style/AppTheme"
            tools:replace="android:icon"
            android:icon="@mipmap/ic_launcher"
            android:name="com.orm.SugarApp">
    

    我也有 com.github.satyan:sugar:1.3 依赖项,我相信库正在其自己的清单中导入另一个图标,从而导致冲突。

    【讨论】:

      猜你喜欢
      • 2016-08-27
      • 2016-08-04
      • 2017-07-23
      • 1970-01-01
      • 2015-08-27
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      相关资源
      最近更新 更多