如何在 AndroidManifest 中自动递增版本代码?
我有已上传到 Subversion/SVN 存储库的应用程序。是否可以使用脚本以某种方式更改存储在 AndroidManifest 中的应用程序版本代码?我的意思是在结账/更新期间/之后?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mypackage"
android:versionCode="100000"
android:versionName="1.0">
I have application which uploaded into Subversion/SVN repo. Is it possible to use script to somehow change application version code stored in AndroidManifest
? I mean during/after checkout/update?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mypackage"
android:versionCode="100000"
android:versionName="1.0">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
SVN 有关键字替换,您可以用于将修订号放入文件中。但是,这将导致清单文件本身上次更改时发生修订,这不是您想要的。
实现您想要的效果的最佳方法是从构建脚本中调用 svnversion ,并将输出嵌入到清单文件中。您可以有一个受版本控制的
manifest.template
文件,构建脚本可以使用它来生成真正的清单文件。在模板中放置一个占位符单词,并将其替换为通过 svnversion 获取的修订号。编辑:在 Eclipse 中,您可能会 使用 Ant 脚本,并在正常构建之前调用它。链接的示例生成一个带有修订号的类文件,但您也可以以非常类似的方式生成清单文件。
SVN has keyword substitution which you can use to put the revision number in a file. However, this will result in the revision when the manifest file itself was last changed, which is not what you want.
The best way to achieve what you want is to call
svnversion
from your build script, and embed the output in the manifest file from there. You could have amanifest.template
file under version control which can be used by your build script to generate the real manifest file. Put a placeholder word in the template and replace it by the revision number obtained withsvnversion
.edit: in Eclipse you would probably use an Ant script, and invoke it before the normal build. The linked example generates a class file with the revision number, but you could also generate a manifest file in a very similar way.
我通过添加额外的构建目标来完成此操作 - 因此版本代码会在构建项目时递增,而不是在提交到 SVN 时递增。这些是使其在 IntelliJ IDEA 中运行的说明。
首先,在项目的根目录中添加一个名为
svn-revision.build.xml
的新文件,其中包含以下内容:然后在菜单中转到
View >工具> Ant Build
,然后按窗口中的小+
按钮并添加新创建的文件。单击 Ant Build 窗口中的绿色“运行”按钮将立即运行脚本。要使脚本在每次构建时运行,您需要将“svn-revision”目标设置为默认目标。I've done this by adding an extra build target - so the version code is incremented when you build the project, not when you commit to SVN. These are instructions to get this to work in IntelliJ IDEA.
First, add a new file in the root of your project called
svn-revision.build.xml
with the following contents:Then in the menu go to
View > Tools > Ant Build
, then press the little+
button in the window and add the newly created file. Clicking the green 'run' button in the Ant Build window will run the script right away. To make the script run every time you build, you will need to set the 'svn-revision' target as a default target.您可以在构建时使用默认 Android 构建脚本提供的 xpath Ant 目标来获取当前值,然后使用 Ant 替换。
You could do it at build time using the xpath Ant target provided by the default Android build scripts to get the current value, then use Ant replace.
SVN 方法很好,但不一定适合所有人。我确实更喜欢控制应用程序 versionName 和 versionCode 增量,因此我做了自己的 Java 简单应用程序来实现此
功能:
可以在这里找到:
Android 清单版本号
SVN approach is fine, but not necessarily suitable for everyone. I do prefer to have control on app versionName and versionCode increment so I did my own Java simple app to do that
Features:
Available here:
android manifest build number