Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android BuildConfig.VERSION_NAME returning null?

Tags:

android

I'd like to simply display my version name on my login screen, however, it's always returning null. I've defined my versionName in my app's gradle build as follows:

    defaultConfig {
    applicationId "com.maplesyrupindustries.j.airportmeet"
    minSdkVersion 19
    targetSdkVersion 24
    versionCode 7
    versionName "1.0.6"
    multiDexEnabled true
}

And I am calling it in my login's onCreate:

    String build = BuildConfig.VERSION_NAME;
    Log.e(TAG, BuildConfig.VERSION_NAME);
    tvVersion.setText("Alpha " + build);

Yet, the build string is always empty. What gives?

like image 812
SpecialSnowflake Avatar asked Aug 10 '16 12:08

SpecialSnowflake


1 Answers

Please try this

PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;//Version Name
int verCode = pInfo.versionCode;//Version Code
like image 113
Abhishek Patel Avatar answered Oct 03 '22 02:10

Abhishek Patel