nAk*_*dov 5 android build gradle android-studio
当我每次运行我的应用程序时,versionName在Manifest文件中递增. 20389表示旧版本名称,20390表示递增编号.

项目建立成功,如BUILD SUCCESSFUL.但问题是为什么Android studio会缓存以前的apk版本.这是什么错误:
目标设备:lge-nexus_5-061642fd00511249上传文件本地路径:H:\ customFolder\app\build\outputs\apk\MyAppName-0.6.200_20383-debug.apk远程路径:/data/local/tmp/com.example.app本地路径不存在.
当应用程序在设备上运行时你注意,android studio尝试安装20383版本的apk.这是错误的.谁能帮助我?我已经googeled并看到了这个链接.
以下是我可以使用gradle脚本更改清单文件的方法:
def updateRevisionNumber () {//autoIncrement Version Name
def currentVersion = getVersionName();
def currentRevisionInManifest = currentVersion.substring(currentVersion.indexOf("_")+1);
def lastRevision = Integer.parseInt(currentRevisionInManifest) + 1;
println("currentRevisionInManifest: " + currentRevisionInManifest);
println("lastRevision: " + lastRevision);
def oldText = manifestFile.getText();
def changedText = oldText.replace(currentRevisionInManifest,lastRevision+"");
manifestFile.setText(changedText);}
Run Code Online (Sandbox Code Playgroud)
您可以覆盖清单的 android 部分中的版本名称,而不是在构建期间编辑清单文件:
android {
...
defaultConfig {
versionName someScriptToComputeVersionName()
...
Run Code Online (Sandbox Code Playgroud)
这样做至少有两个充分的理由:
现在你的问题是正确定义函数someScriptToComputeVersionName(),这取决于你。
IMO,简单地增加数字可能不是最好的选择,如果您基于 VCS 修订号构建版本名称,您可能应该寻求解决方案。
| 归档时间: |
|
| 查看次数: |
477 次 |
| 最近记录: |