Android studio 1.5.1: Could not find property 'vectorDrawables'
F

4

7

I'm using Android Studio 1.5.1, Gradle 2.8 and my project min sdk vserion:14, target sdk version: 23.

So, When I add vectorDrawables to configuration by documentation Google: Added VectorDrawable support library, I get following error:

Error:(13, 0) Could not find property 'vectorDrawables' on ProductFlavor_Decorated{name=main, dimension=null, minSdkVersion=ApiVersionImpl{mApiLevel=14, mCodename='null'}, targetSdkVersion=ApiVersionImpl{mApiLevel=23, mCodename='null'}, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptNdkModeEnabled=null, versionCode=25, versionName=1.0.25, applicationId=com.smsoft.alibaba, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRunnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}}.

this is my build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.smsoft.alibaba"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 25
        versionName "1.0.25"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:23.2.0'
     compile 'com.android.support:design:23.2.0'
     compile 'com.android.support:support-v4:23.2.0'
     compile 'com.android.support:cardview-v7:23.2.0'
}

Anybody know how to fix this problem ?

EDIT

Thanks to @Gabriele Mariotti to signal for my confused between gradle and gradle plugin. I'm confused when reading the addition of Compact Vector Drawables instructions.

Fanchet answered 29/2, 2016 at 6:34 Comment(0)
F
21

If you’re using v2.0 or above of the Gradle plugin you have to use:

android {
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
}

If you hare using v1.5.0 or below of the Gradle plugin you need to add the following to your app’s build.gradle:

android {
  defaultConfig {
    // Stops the Gradle plugin’s automatic rasterization of vectors
    generatedDensities = []
  }
  // Flag to tell aapt to keep the attribute ids around
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

Don't confuse gradle with the gradle plugin. Check the build.gradle in the root folder (or inside the module) to get the version used by the gradle plugin (check the line classpath 'com.android.tools.build:gradle:1.5.0')

Foumart answered 29/2, 2016 at 7:33 Comment(8)
Hi @Gabriele, I fixed my question and I forget add "vectorDrawables.useSupportLibrary = true" line to defaultConfig, after adding this line I got this error, look to aboveFanchet
Are you using the plugin 2.0 ?Foumart
@mr.boyfox Don't confuse gradle with the gradle plugin. 2.8 is the gradle version, not the plugin. Check the build.gradle in the root folder.Foumart
Oh, sorry you are right i use com.android.tools.build:gradle:1.5.0 build pluginFanchet
i dont get it. im using gradle 2+ still having the same error as OPPromptitude
Your comments did the trick for me. Like @mr.boyfox was confused between gradle and gradle pugin.Gulledge
@GabrieleMariotti Great if you could add this information to your answer as well.Gulledge
@Gulledge just added in the answer.Foumart
F
5

Specifically to upgrade from com.android.tools.build:gradle:1.5.0.

  1. Edit /build.gradle and set:

    buildscript {
        ...
        dependencies {
            ...
            classpath 'com.android.tools.build:gradle:2.0.0'
            ...
        }
    }
    
  2. Edit /gradle/wrapper/gradle-wrapper.properties and set:

    distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
    
  3. Edit your module(s)' build.gradle and add:

    android {
        ...
        defaultConfig {
            ...
            vectorDrawables.useSupportLibrary = true
        }
        ...
    }
    
Fronton answered 6/4, 2016 at 21:55 Comment(1)
BTW, this may be off-topic, but today (2016/04/08) there is a mysterious comment about Support 23.3 that removes this feature from AppCompat pre-Lollipop devices: plus.google.com/+AndroidDevelopers/posts/iTDmFiGrVne Funny that there is no mention of this removal in the official release notes (that the above posting gives a link to): developer.android.com/tools/support-library/index.htmlFronton
H
0

I experienced this issue with Gradle plugin on v3.4.2. It prevented project sync's from completing.

The issue was resolved by removing vectorDrawables and adding vectorDrawables.useSupportLibrary = true to the defaultConfig.

OLD

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.android.diceroller"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }vectorDrawables
}

NEW

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.android.diceroller"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}
Hatchet answered 1/8, 2019 at 15:25 Comment(0)
G
0

If u are having useSupportLibary in latest version Use

vectorDrawables.useSupportLibary(true)
In your defaultconfig 
Guardroom answered 7/6, 2020 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.