我只想在我的登录屏幕上显示我的版本名称,但是,它总是返回 null。我在我的应用程序的 gradle 构建中定义了我的版本名称,如下所示:
defaultConfig {
applicationId "com.maplesyrupindustries.j.airportmeet"
minSdkVersion 19
targetSdkVersion 24
versionCode 7
versionName "1.0.6"
multiDexEnabled true
}
我在登录的 onCreate 中调用它:
String build = BuildConfig.VERSION_NAME;
Log.e(TAG, BuildConfig.VERSION_NAME);
tvVersion.setText("Alpha " + build);
然而,构建字符串始终为空。给了什么?
最佳答案
请试试这个
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;//Version Name
int verCode = pInfo.versionCode;//Version Code
关于Android BuildConfig.VERSION_NAME 返回空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38872907/