問題描述
我需要弄清楚如何為我的 Android 應(yīng)用程序獲取或制作內(nèi)部版本號(hào).我需要在 UI 中顯示內(nèi)部版本號(hào).
I need to figure out how to get or make a build number for my Android application. I need the build number to display in the UI.
我必須對 AndroidManifest.xml
做些什么嗎?
Do I have to do something with AndroidManifest.xml
?
推薦答案
如果你使用 Gradle 插件/Android Studio,從版本 0.7.0 開始,版本代碼和版本名稱在 BuildConfig
中靜態(tài)可用.確保您導(dǎo)入應(yīng)用的包,而不是另一個(gè) BuildConfig
:
If you're using the Gradle plugin/Android Studio, as of version 0.7.0, version code and version name are available statically in BuildConfig
. Make sure you import your app's package, and not another BuildConfig
:
import com.yourpackage.BuildConfig;
...
int versionCode = BuildConfig.VERSION_CODE;
String versionName = BuildConfig.VERSION_NAME;
不需要上下文對象!
還要確保在 build.gradle
文件而不是 AndroidManifest.xml
中指定它們.
Also make sure to specify them in your build.gradle
file instead of the AndroidManifest.xml
.
defaultConfig {
versionCode 1
versionName "1.0"
}
這篇關(guān)于如何獲取 Android 應(yīng)用程序的構(gòu)建/版本號(hào)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!