问题描述
我使用的是Android Studio 1.5.1,Gradle 2.8和我的项目min sdk vserion:14,target sdk version:23.
所以,当我添加vectorDrawables通过文档配置Google:,我得到以下错误: 错误:(13,0)无法在ProductFlavor_Decorated上找到属性'vectorDrawables'{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 {
applicationIdcom.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'
}
}
}
依赖项{
编译fileTree(dir:'libs',include:[ '* .jar'])
testCompile'junit:junit:4.12'
compile'com.android.support:appcompat-v7:23.2.0'
compile'com.android.support :设计:23.2.0'
编译'com.android.support:support-v4:23.2.0'
编译'com.android.support:cardview-v7:23.2.0'
}
有人知道如何解决这个问题吗?
编辑
感谢@Gabriele Mariotti发信号给我的gradle和gradle插件之间的混淆。如果您使用的是 v2.0版本,则可以使用 v2.0版本。
您必须使用 Gradle插件 : $ b defaultConfig {vectorDrawables.useSupportLibrary = true
}
}
如果您使用的是 v1.5.0 或以下的 Gradle插件,则需要将以下内容添加到您的应用的 build.gradle $
android {
defaultConfig {
//停止Gradle插件的自动栅格化向量
generatedDensities = []
}
//标记以告诉aapt保持属性id在
附近aaptOptions {
additionalParameters--no-version-vectors
}
}
不要将gradle与gradle插件混淆。检查根文件夹(或模块内部)中的 build.gradle
以获取gradle插件使用的版本(检查 classpath'com .android.tools.build:gradle:1.5.0'
)
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.
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'
)
这篇关于Android Studio 1.5.1:找不到属性'vectorDrawables'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!