无法找到属性' VERSION_CODE'错误:(21,0)

时间:2016-04-21 21:46:16

标签: android android-studio gradle

我正在尝试在Android Studio 1.5.1中导入项目。我首先删除了com.android.application'的一个错误。没找到,但后来这个错误已经上升。 enter image description here

  

Gradle sync失败:无法找到属性' VERSION_CODE'上   ProductFlavor_Decorated {name = main,dimension = null,   minSdkVersion = DefaultApiVersion {mApiLevel = 14,mCodename =' null'},   targetSdkVersion = DefaultApiVersion {mApiLevel = 23,mCodename =' null'},   renderscriptTargetApi = null,renderscriptSupportModeEnabled = null,   renderscriptNdkModeEnabled = null,versionCode = null,versionName = null,   的applicationID = com.fractalwrench.androidbootstrap.sample,   testApplicationId = null,testInstrumentationRunner = null,   testInstrumentationRunnerArguments = {},testHandleProfiling = null,   testFunctionalTest = null,signingConfig = null,resConfig = null,   mBuildConfigFields = {},mResValues = {},mProguardFiles = [],   mConsumerProguardFiles = [],mManifestPlaceholders = {}}。

1 个答案:

答案 0 :(得分:3)

The problem is with the VERSION_CODE and VERSION_NAME. I guess they are missing in your project. You can hardcode the version code and version name like this -

versionCode 21
versionName "1.0"

or can make it dynamic like this -

def versionMajor = 1
def versionMinor = 1
def versionBuild = 0
defaultConfig {
  versionCode versionMajor * 1000000 + versionMinor * 10000 + versionBuild * 100
  versionName "${versionMajor}.${versionMinor}.${versionBuild}"
}
相关问题