toto_tata
toto_tata

Reputation: 15392

Android Studio : "Could not get unknown property 'VERSION_NAME' for project of type org.gradle.api.Project"

I am a newbie with Android Studio. I am trying to use this project library : https://github.com/2dxgujun/AndroidTagGroup in my project.

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."

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 ?

Thanks !!!

Upvotes: 6

Views: 52891

Answers (3)

hicus
hicus

Reputation: 1

I had a similar problem. 'VERSION_NAME' was not defined in the ext{} from build.gradle(Project: 'PROJECT_NAME')

Upvotes: 0

HandyPawan
HandyPawan

Reputation: 1106

buildscript {
    ext.kotlin_version = '1.3.31'
    ext.room_version = '2.1.0-alpha01' // Add this line in your build gradle
    repositories {
        google()
        jcenter()

    }

Upvotes: 1

WarrenFaith
WarrenFaith

Reputation: 57672

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

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:

versionCode Integer.parseInt(project.VERSION_CODE)

Fix is the same: provide a valid self defined variable or constant

Upvotes: 5

Related Questions