如果我们已经在app/build.gradle中设置了AndroidManifest.xml中的versionCode和versionName,那还需要什么?

What is the need of versionCode and versionName in AndroidManifest.xml if we already set it in app/build.gradle?

我们真的需要在 AndroidManifest.xml 中包含 android:versionCodeandroid:versionName 吗?

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.my.application"
  android:versionCode="1"
  android:versionName="1.0.0">

这些值显示在我的 App/build.gradle 下的 defaultConfig 中。我认为将它们放在 AndroidManifest 中没有任何价值。我从同事那里收到的论点是,当用户点击它时,这个值稍后会显示在 AppInfo 中。

根据 Android docs,我在 Android Manifest 中也没有看到关于这些设置的任何突出显示。

official doc所述:

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.