Java Android Studio:“无法获得类型为 org.gradle.api.Project 的项目的未知属性‘VERSION_NAME’”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40420705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio : "Could not get unknown property 'VERSION_NAME' for project of type org.gradle.api.Project"
提问by Regis_AG
I am a newbie with Android Studio. I am trying to use this project library : https://github.com/2dxgujun/AndroidTagGroupin my project.
我是 Android Studio 的新手。我正在尝试在我的项目中使用这个项目库:https: //github.com/2dxgujun/AndroidTagGroup。
So what I did is to import it as a module in my project ; with the name "androidtaggroup"
所以我所做的是将它作为一个模块导入到我的项目中;名称为“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."
Here is where the problem occurs in the Gradle file:
以下是 Gradle 文件中出现问题的地方:
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 ?
任何人都可以告诉我如何解决这个问题?
Thanks !!!
谢谢 !!!
采纳答案by WarrenFaith
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.
解决方法是在那里定义您的版本名称或使用自定义变量。project.VERSION_NAME
默认情况下不存在,因此您不能使用它。这基本上就是错误消息告诉你的。
defaultConfig {
applicationId 'me.gujun.android.taggroup.demo'
minSdkVersion 8
targetSdkVersion 21
versionName "1.2.3"
versionCode Integer.parseInt(project.VERSION_CODE)
}
or alternative:
或替代:
// 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)
}
And after you have changed that you will probably run into the same issue for using project.VERSION_CODE
:
在您更改之后,您可能会遇到相同的问题project.VERSION_CODE
:
versionCode Integer.parseInt(project.VERSION_CODE)
Fix is the same: provide a valid self defined variable or constant
修复是一样的:提供一个有效的自定义变量或常量
回答by HandyPawan
buildscript {
ext.kotlin_version = '1.3.31'
ext.room_version = '2.1.0-alpha01' // Add this line in your build gradle
repositories {
google()
jcenter()
}
回答by hicus
I had a similar problem. 'VERSION_NAME' was not defined in the ext{} from build.gradle(Project: 'PROJECT_NAME')
我有一个类似的问题。'VERSION_NAME' 未在 build.gradle 的 ext{} 中定义(项目:'PROJECT_NAME')