15

All was fine until i updated the android studio to Canary 6, When i rebuild or clean or whatever with project it's throw :

A failure occurred while executing com.android.build.gradle.tasks.MergeResources$FileGenerationWorkAction

And this error guide me to my vectors.xml [All of them got this error] .

My Current app level 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'
}

Also when i tried to download com.android.support libraries, The IDE just search for the sdk and just do nothing.

What i have been tried :

  • Clean and Rebuild.

  • Invalidate Caches.

Rivu Chakraborty
  • 1,372
  • 2
  • 12
  • 37

7 Answers7

66

The advantage of adding a multi-density vector graphic is to use a vector instead of a bitmap to reduce the size of the APK because the size of the same file can be adjusted for different screen densities without loss off image quality. For older versions of Android that don't support vector drawables, Vector Asset Studio can, at build time, turn your vector drawables into different bitmap sizes for each screen density

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

build.gradle

android {
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
}
Dexter
  • 754
  • 6
  • 14
10

Adding vectorDrawables.useSupportLibrary = true to defaultConfig of build.gradle(Module) worked for me. :)

4

I had the same issue. There were two ways to fix my case:

  1. Adding vectorDrawables.useSupportLibrary = true
  2. In my drawable vector xml files there were links to @color:

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

    I replaced with

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

    and the problem disappeared.

Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53
2

There is a lot problems with android studio canary 6, the best way to solve that is to change your class path in the dependencies in your gradle to

classpath 'com.android.tools.build:gradle:2.3.3' 
Mohad12211
  • 353
  • 3
  • 9
  • you sure that `2.3.3` version will work with the build ecxution ? –  Jul 12 '17 at 22:01
  • I changed the classpath to 2.3.3 in android studio canary 6 without any problems. – Mohad12211 Jul 12 '17 at 22:03
  • The problem has nothing to do with the Android Studio or Gradle build version. It happens in Android Studio 3.0 release build too. The solution is the vectorDrawables.useSupportLibrary = true flag mentioned in the other answers. – Minsky Dec 13 '17 at 14:00
2

Just add vectorDrawables.useSupportLibrary = true in defaultConfig, it's work fine for me

defaultConfig {
        vectorDrawables.useSupportLibrary = true
}
shams keshk
  • 33
  • 1
  • 6
0

add this to your build.gradle under defaultConfig

vectorDrawables.useSupportLibrary = true .

this will solve your problem.

Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
0

The issue is with build gradle 3.1.4. Downgrade to 3.1.3 and you should be good to go

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
}
  • Downgrades are usually tricky. It is better to think of solutions under the assumption of backwards compatibility... – storaged Aug 22 '18 at 10:32