Now you can put versionCode
and versionName
in both build.gradle
and AndroidManifest.xml
files. Which of them is the best place to put these attributes, and why is it better than the other option?
I can't find any info about this in google official documentation:
https://developer.android.com/tools/building/configuring-gradle.html
http://developer.android.com/guide/topics/manifest/manifest-element.html
Thanks a lot.
It doesn't actually differ. But I'll tell you some info about that.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With