1. 程式人生 > >android 開發中獲取versionName和versionCode

android 開發中獲取versionName和versionCode

android studio中gradle檔案和manifest中都有對於versionName和versionCode的配置。

經過實踐發現使用PocketManager get PocketInfo中的versionName是gradle配置的,查閱官方文件發現gradle中的配置在build的時候會覆蓋manifest中的。

To define the version information for your app, set values for the version settings in the Gradle build files. These values are then merged into your app's manifest file during the build process.

Note: If your app defines the app version directly in the <manifest> element, the version values in the Gradle build file will override the settings in the manifest. Additionally, defining these settings in the Gradle build files allows you to specify different values for different versions of your app. For greater flexibility and to avoid potential overwriting when the manifest is merged, you should remove these attributes from the <manifest>

 element and define your version settings in the Gradle build files instead.

Two settings are available, and you should always define values for both of them:

所以可以刪除manifest中的配置,直接使用gradle中的配置。