Android studio 1.5.1:找不到属性“vectorDrawables" [英] Android studio 1.5.1: Could not find property 'vectorDrawables'

查看:22
本文介绍了Android studio 1.5.1:找不到属性“vectorDrawables"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Android Studio 1.5.1、Gradle 2.8 和我的项目 min sdk vserion:14,目标 sdk 版本:23.

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

因此,当我通过 Google 文档将 vectorDrawables 添加到配置时:添加了 VectorDrawable 支持库,我收到以下错误:

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={}}.

这是我的 build.gradle 文件:

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 ?

编辑

感谢@Gabriele Mariotti 指出我对 gradle 和 gradle 插件的困惑.阅读Compact Vector Drawables指令的添加时,我很困惑.

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.

推荐答案

如果您使用 v2.0 或更高版本的 Gradle 插件,您必须使用:

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

android {
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
}

如果您使用 v1.5.0 或更低版本的 Gradle 插件,您需要将以下内容添加到您应用的 build.gradle:

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"
  }
}

不要将 gradle 与 gradle 插件混淆.检查根文件夹(或模块内部)中的 build.gradle 以获取 gradle 插件使用的版本(检查行 classpath 'com.android.tools.build:gradle:1.5.0')

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')

这篇关于Android studio 1.5.1:找不到属性“vectorDrawables"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆