Android BuildConfig.VERSION_NAME returning null?

Please try this

PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;//Version Name
int verCode = pInfo.versionCode;//Version Code

BuildConfig.VERSION_NAME is not working 
1). In Case when you import Wrong Package Please check your import Package 
2). Please import your application package & solve this issue permanently


  PackageInfo pInfo = null;
  try {
       pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }   

 String versionName = pInfo.versionName;//Version Name
 int versionCode = pInfo.versionCode;//Version Code

 Log.e("keshav"," VERSION_NAME -->" + versionName +"versionCode -> "+versionCode);

Output

E/keshav:  VERSION_NAME -->2.0.4  versionCode -> 26

enter image description here

Tags:

Android