Better place to put versionCode/versionName? build.gradle vs AndroidManifest.xml

Here you can find the official doc.

Pay attention that Gradle overrides the info in the AndroidManifest.xml
I suggest you using always the gradle script to set these values.

If a property is not set through the DSL, some default value will be used. Here’s a table of how this is processed.

 Property Name   Default value in DSL object     Default value
 versionCode     -1                              value from manifest if present
 versionName     null                            value from manifest if present

It doesn't actually differ. But I'll tell you some info about that.

  1. If you have written your versionCode and versionName in both your AppManifest.xml and build.gradle, the ones written in build.gradle will replace the ones in your AppManifest.xml when you compile your app, and here comes point 2.

  2. If you haven't written them in your AppManifest.xml, when you compile your app and build it, your versionCode and versionName written in your build.gradle will automatically be written in your AppManifest.xml.

  3. And if you have written them in your AppManifest.xml only, nothing will happen. It is already written...

So as a summary, build.gradle overrides your AppManifest.xml.

Hope that helps.

Source: https://developer.android.com/studio/publish/versioning

Note: If your app defines the app version directly in the 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 element and define your version settings in the Gradle build files instead.