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"

查看:39
本文介绍了Android Studio:“无法获得类型为 org.gradle.api.Project 的项目的未知属性‘VERSION_NAME’"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆