15

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

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

这个错误将我引导到我的vectors.xml[All of them got this error] 。

我当前的应用程序级别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 而什么也不做。

我已经尝试过:

  • 清洁和重建。

  • 使缓存无效。

4

7 回答 7

65

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

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

构建.gradle

android {
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
}
于 2017-07-27T10:38:42.930 回答
10

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

于 2017-09-26T09:58:12.913 回答
4

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

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

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

    我替换为

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

    问题消失了。

于 2017-10-26T02:51:25.123 回答
2

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

classpath 'com.android.tools.build:gradle:2.3.3' 
于 2017-07-12T21:56:58.893 回答
2

只需在 defaultConfig 中添加 vectorDrawables.useSupportLibrary = true,它对我来说很好用

defaultConfig {
        vectorDrawables.useSupportLibrary = true
}
于 2017-10-31T00:44:59.573 回答
0

将此添加到您的build.gradledefaultConfig

vectorDrawables.useSupportLibrary = true.

这将解决您的问题。

于 2018-05-18T12:36:22.913 回答
0

问题在于构建 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
}
于 2018-08-22T10:24:15.197 回答