Android Studio:“无法获得类型为org.gradle.api.Project的项目的未知属性'VERSION_NAME'"; [英] Android Studio : "Could not get unknown property 'VERSION_NAME' for project of type org.gradle.api.Project"
问题描述
我是Android Studio的新手.我正在尝试使用此项目库:在我的 https://github.com/2dxgujun/AndroidTagGroup 项目.
I am a newbie with Android Studio. I am trying to use this project library : https://github.com/2dxgujun/AndroidTagGroup in my project.
所以我要做的是将其作为模块导入我的项目中;名称为"androidtaggroup"
So what I did is to import it as a module in my project ; with the name "androidtaggroup"
现在,我在编译时遇到以下错误:
Now, I have got the following error at compilation:
"Could not get unknown property 'VERSION_NAME' for project ':androidtaggroup' of type org.gradle.api.Project."
在此处是Gradle文件中出现问题的地方:
Here is where the problem occurs in the Gradle file:
defaultConfig {
applicationId 'me.gujun.android.taggroup.demo'
minSdkVersion 8
targetSdkVersion 21
versionName project.VERSION_NAME // ERROR HERE !!!!
versionCode Integer.parseInt(project.VERSION_CODE)
}
任何人都可以告诉我如何解决此问题吗?
Anybody can tell me how to fix this problem ?
谢谢!!!
推荐答案
解决方法是在此处定义您的版本名称或使用自定义变量. project.VERSION_NAME
默认情况下不存在,因此您不能使用它.这基本上就是错误消息告诉您的内容.
The fix is to define your version name there or use a custom made variable. project.VERSION_NAME
does not exists by default, therefore you can't use it. That is basically what the error message is telling you.
defaultConfig {
applicationId 'me.gujun.android.taggroup.demo'
minSdkVersion 8
targetSdkVersion 21
versionName "1.2.3"
versionCode Integer.parseInt(project.VERSION_CODE)
}
或替代方法:
// somewhere above
def VERSION_NAME = "1.2.3"
// and the usage:
defaultConfig {
applicationId 'me.gujun.android.taggroup.demo'
minSdkVersion 8
targetSdkVersion 21
versionName VERSION_NAME
versionCode Integer.parseInt(project.VERSION_CODE)
}
更改后,使用project.VERSION_CODE
可能会遇到相同的问题:
And after you have changed that you will probably run into the same issue for using project.VERSION_CODE
:
versionCode Integer.parseInt(project.VERSION_CODE)
修复相同:提供有效的自定义变量或常量
Fix is the same: provide a valid self defined variable or constant
这篇关于Android Studio:“无法获得类型为org.gradle.api.Project的项目的未知属性'VERSION_NAME'";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!