Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !!!

like image 541
Regis_AG Avatar asked Nov 04 '16 10:11

Regis_AG


2 Answers

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

like image 168
WarrenFaith Avatar answered Oct 13 '22 03:10

WarrenFaith


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

    }
like image 21
HandyPawan Avatar answered Oct 13 '22 04:10

HandyPawan