简体   繁体   English

放置版本代码/版本名称的更好地方? build.gradle 与 AndroidManifest.xml

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

Now you can put versionCode and versionName in both build.gradle and AndroidManifest.xml files.现在您可以将versionCodeversionName放在build.gradleAndroidManifest.xml文件中。 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:我在谷歌官方文档中找不到任何关于此的信息:

  1. https://developer.android.com/tools/building/configuring-gradle.html https://developer.android.com/tools/building/configuring-gradle.html

  2. http://developer.android.com/guide/topics/manifest/manifest-element.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.但我会告诉你一些有关的信息。

  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.如果您在 AppManifest.xml 和 build.gradle 中都编写了 versionCode 和 versionName,那么在编译应用程序时,build.gradle 中编写的将替换 AppManifest.xml 中的那些,这就是第 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.如果你没有在你的 AppManifest.xml 中写入它们,当你编译你的应用并构建它时,你在 build.gradle 中写入的 versionCode 和 versionName 将自动写入你的 AppManifest.xml。

  3. And if you have written them in your AppManifest.xml only, nothing will happen.如果您只在 AppManifest.xml 中编写了它们,则不会发生任何事情。 It is already written...已经写好了...

So as a summary, build.gradle overrides your AppManifest.xml.因此,总而言之,build.gradle会覆盖您的 AppManifest.xml。

Hope that helps.希望有帮助。

Source: https://developer.android.com/studio/publish/versioning来源: 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.注意:如果您的应用直接在元素中定义应用版本,则 Gradle 构建文件中的版本值将覆盖清单中的设置。 Additionally, defining these settings in the Gradle build files allows you to specify different values for different versions of your app.此外,在 Gradle 构建文件中定义这些设置允许您为应用程序的不同版本指定不同的值。 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.为了获得更大的灵活性并避免在合并清单时潜在的覆盖,您应该从元素中删除这些属性并改为在 Gradle 构建文件中定义您的版本设置。

Here you can find the official doc .在这里你可以找到官方文档

Pay attention that Gradle overrides the info in the AndroidManifest.xml注意 Gradle会覆盖AndroidManifest.xml的信息
I suggest you using always the gradle script to set these values.我建议您始终使用 gradle 脚本来设置这些值。

If a property is not set through the DSL, some default value will be used.如果属性不是通过 DSL 设置的,则将使用一些默认值。 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

Using Gradle, I can't recall any situation where I had to use the version from the AndroidManifest.xml .使用 Gradle,我想不起来我必须使用AndroidManifest.xml的版本的任何情况。

My first thought would be to just remove the version from AndroidManifest.xml , and use the one coming from build.gradle .我的第一个想法是从AndroidManifest.xml删除版本,并使用来自build.gradle

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我们已经在 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? Android Studio AndroidManifest.xml 与 build.gradle - Android Studio AndroidManifest.xml vs build.gradle build.gradle 和 AndroidManifest.xml 在哪里 - Where are build.gradle and AndroidManifest.xml 构建项目时,AndroidManifest.xml 文件中的 versionCode 和 versionName 会被默认值覆盖 - versionCode and versionName in AndroidManifest.xml file are overwritten with default values when project is built Android studio:为什么在AndroidManifest.xml 和build.gradle 中都指定了minSdkVersion 和targetSdkVersion? - Android studio: why are minSdkVersion and targetSdkVersion specified both in AndroidManifest.xml and build.gradle? 我应该从build.gradle还是AndroidManifest.xml管理应用程序版本控制? - Should I manage app versioning from build.gradle or AndroidManifest.xml? React Native - 对 build.gradle 或 AndroidManifest.xml 的更改是否会通过快速刷新进行更新? - React Native - do changes to build.gradle or AndroidManifest.xml get updated with fast refresh? Androidmanifest.xml文件中的gradle构建错误 - gradle build error in Androidmanifest.xml file 代码中AndroidManifest.xml的用户versionName值 - User versionName value of AndroidManifest.xml in code 在build.gradle中访问versionName - Access versionName in build.gradle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM