我正在使用Android Studio 1.5.1,Gradle 2.8和我的项目min sdk vserion:14,目标sdk版本:23.
所以,当我通过文档Google添加vectorDrawables配置时:添加了VectorDrawable支持库,我收到以下错误:
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' }
有谁知道如何解决这个问题?
编辑
感谢@Gabriele Mariotti表示我在gradle和gradle插件之间感到困惑.在阅读Compact Vector Drawables指令的添加时,我很困惑.
如果您使用的是Gradle插件的v2.0或更高版本,则必须使用:
android { defaultConfig { vectorDrawables.useSupportLibrary = true } }
如果您使用的是Gradle插件的v1.5.0或更低版本,则需要将以下内容添加到您的应用中: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'
)
专门升级com.android.tools.build:gradle:1.5.0
.
编辑/build.gradle并设置:
buildscript { ... dependencies { ... classpath 'com.android.tools.build:gradle:2.0.0' ... } }
编辑/gradle/wrapper/gradle-wrapper.properties并设置:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
编辑您的模块'build.gradle并添加:
android { ... defaultConfig { ... vectorDrawables.useSupportLibrary = true } ... }