【问题标题】:Android studio 3.0 Canary 6 A failure occurred while executing com.android.build.gradle.tasks.MergeResources$FileGenerationWorkActionAndroid studio 3.0 Canary 6 执行 com.android.build.gradle.tasks.MergeResources$FileGenerationWorkAction 时发生故障
【发布时间】:2017-07-12 21:28:28
【问题描述】:

在我将 android studio 更新到 Canary 6 之前,一切都很好,当我重建或清理或其他项目时,它会抛出:

执行 com.android.build.gradle.tasks.MergeResources$FileGenerationWorkAction 时发生故障

这个错误引导我找到我的vectors.xml [他们都得到了这个错误] .

我当前的应用级别build.gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "example.project"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 42
        versionName "1.3"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        //multiDexEnabled = true
    }
    buildTypes {
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
}


dependencies {

    compile 'com.android.support:appcompat-v7:25.3.1'//<-- can't update to new one
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.android.support:support-v13:25.3.1'
    compile 'com.android.support:palette-v7:25.3.1'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.squareup.okhttp3:okhttp:3.0.1'
    compile 'com.android.support:multidex:1.0.1'
    testCompile 'junit:junit:4.12'
}

另外,当我尝试下载 com.android.support 库时,IDE 只是搜索 sdk,什么也不做。

我已经尝试过什么:

  • 清理并重建。

  • 使缓存无效。

【问题讨论】:

  • android studio canary 6 存在很多问题,我建议你使用 android studio 2.3.3 或将依赖项中的类路径更改为 2.3.3
  • Canary 4 比 5/6 更稳定,特别是如果你使用 Kotlin + ConstraintLayout。

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


【解决方案1】:

添加多密度矢量图的好处是使用矢量而不是位图来减小 APK 的大小,因为同一文件的大小可以针对不同的屏幕密度进行调整而不会损失图像质量。对于不支持矢量绘图的旧版本 Android,Vector Asset Studio 可以在构建时将您的矢量绘图转换为每个屏幕密度的不同位图大小

 classpath 'com.android.tools.build:gradle:3.0.0-alpha8

build.gradle

android {
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
}

【讨论】:

    【解决方案2】:

    vectorDrawables.useSupportLibrary = true 添加到 build.gradle(Module) 的 defaultConfig 对我有用。 :)

    【讨论】:

      【解决方案3】:

      我有同样的问题。有两种方法可以解决我的问题:

      1. 添加vectorDrawables.useSupportLibrary = true
      2. 在我的可绘制矢量 xml 文件中,有指向 @color 的链接:

        <path
            android:fillColor="@color/white"
            ...
        

        我换成

        <path
            android:fillColor="#fff"
            ...
        

        问题就消失了。

      【讨论】:

        【解决方案4】:

        android studio canary 6 存在很多问题,解决这个问题的最好方法是将你的 gradle 中的依赖项中的类路径更改为

        classpath 'com.android.tools.build:gradle:2.3.3' 
        

        【讨论】:

        • 您确定 2.3.3 版本可以与构建 ecxution 一起使用吗?
        • 我在 android studio canary 6 中将类路径更改为 2.3.3 没有任何问题。
        • 该问题与Android Studio或Gradle构建版本无关。它也发生在 Android Studio 3.0 发布版本中。解决方案是其他答案中提到的 vectorDrawables.useSupportLibrary = true 标志。
        【解决方案5】:

        只需在 defaultConfig 中添加 vectorDrawables.useSupportLibrary = true,对我来说就可以了

        defaultConfig {
                vectorDrawables.useSupportLibrary = true
        }
        

        【讨论】:

          【解决方案6】:

          将此添加到您的build.gradle defaultConfig

          vectorDrawables.useSupportLibrary = true

          这将解决您的问题。

          【讨论】:

            【解决方案7】:

            问题在于构建 gradle 3.1.4。降级到 3.1.3,你应该很高兴

            dependencies {
                classpath 'com.android.tools.build:gradle:3.1.3'
                // NOTE: Do not place your application dependencies here; they belong
                // in the individual module build.gradle files
            }
            

            【讨论】:

            • 降级通常很棘手。最好在向后兼容的假设下考虑解决方案...
            猜你喜欢
            • 2021-07-29
            • 2020-07-05
            • 1970-01-01
            • 2019-12-27
            • 2020-09-19
            • 1970-01-01
            • 2022-08-21
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多