android gradle 本地路径不存在

标签 android android-studio build gradle

当我每次运行我的应用程序时,Manifest 文件中的 versionName 都会递增。 20389 表示旧版本名称,20390 是递增的数字。

enter image description here

项目构建成功,如BUILD SUCCESSFUL。但问题是为什么Android studio 会缓存以前的apk 版本。这是错误的地方:

Target device: lge-nexus_5-061642fd00511249 Uploading file local path: H:\customFolder\app\build\outputs\apk\MyAppName-0.6.200_20383-debug.apk remote path: /data/local/tmp/com.example.app Local path doesn't exist.

当你注意到应用程序在设备上运行时,android studio 会尝试安装 20383 版本的 apk。这是错误的。谁能帮帮我?我用谷歌搜索并看到了这个 link .

这是我如何使用 gradle 脚本更改 list 文件:

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);}

最佳答案

无需在构建期间编辑您的 list 文件,您可以覆盖 list 的 android 部分中的版本名称:

android {
    ...
    defaultConfig {
        versionName someScriptToComputeVersionName()
        ...

这样做至少有两个充分的理由:

  • 构建过程不会更改您的源代码(即 AndroidManifest.xml 不会被修改 - 至少您的可编辑源代码中的 AndroidManifest.xml 不会被修改)
  • Android Studio 很可能会满意。

现在您的问题是正确定义函数 someScriptToComputeVersionName() ,这取决于您。

IMO,简单地增加一个数字可能不是最好的选择,如果您根据 VCS 修订号构建版本名称,您可能应该寻求解决方案。

关于android gradle 本地路径不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30053091/

相关文章:

android - 错误 : Program type already present: android. support.v4.accessibilityservice.AccessibilityServiceInfoCompat

testing - 我们可以取消选中 Run custom build in teamcity 中的任何构建步骤吗

android - Gradle 构建成功且没有错误,但在 build.gradle (app) 页面上仍然显示错误

flutter 错误未定义类 'RenderContext'

android-studio - 无法解决编译 'org.jsoup:jsoup:1.7.3'

xcode 4 build设置说明

java - Android 中加密文本时解密返回空字符串

android - 如何保存在 xml 文件中的对话框窗口中动态创建的 editText 值? - 安卓

android - 从 Assets 文件夹加载 CSS JS

android - 为什么android studio无法检测到我的手机进行调试?