Java Android Studio: “cannot get unknown attribute ‘version_name’ of project of type org.gradle.api.project”

I'm new to Android studio. I'm trying to use the project library in my project: https://github.com/2dxgujun/AndroidTagGroup.

So what I have to do is import it into my project as a module; The name is "Android taggroup"

Now, the following error occurs at compile time:

"Could not get unkNown property 'VERSION_NAME' for project ':androidtaggroup' of type org.gradle.api.Project."

This is where the problem occurred 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)
    }

Who can tell me how to solve this problem?

thank you!!!

resolvent:

The solution is to define your version name here or use the custom variable. Project.version_ Name doesn't exist by default, so you can't use it. This is basically what the error message tells you

defaultConfig {
    applicationId 'me.gujun.android.taggroup.demo'
    minSdkVersion 8
    targetSdkVersion 21
    versionName "1.2.3"
    versionCode Integer.parseInt(project.VERSION_CODE)
}

Or substitute:

// 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)
}

After the change, you may use project.version_ Code encountered the same problem:

versionCode Integer.parseInt(project.VERSION_CODE)

The fix is the same: provide a valid custom variable or constant

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>