首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在构建时重命名的APK不会运行

在构建时重命名的APK不会运行
EN

Stack Overflow用户
提问于 2016-01-11 21:05:25
回答 1查看 426关注 0票数 2

我在模块的build.gradle文件中使用此代码来重命名输出APK

代码语言:javascript
运行
复制
android.applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def file = output.outputFile
                def formattedDate = new Date().format('yyyy_MM_dd_HH_mm')
                output.outputFile = new File(file.parent, file.name.replace(".apk",
                        "-" + formattedDate + ".apk"))
            }
        }

当我按下" Run“时,我在build/outputs/apk/app-debug-2016_01_11_13_23.apk收到APK,并在Run console中得到一个错误:

代码语言:javascript
运行
复制
The APK file .../build/outputs/apk/app-debug-2016_01_11_13_21.apk does not exist on disk.

每次当我按下"Run“时,我都会在/build/outputs/apk/文件夹中收到新的APK,但错误是相同的。看起来Android Studio使用的是应用程序名称的旧值。

我使用这个运行配置:

请随时给出任何类型的建议。

EN

回答 1

Stack Overflow用户

发布于 2016-04-07 01:14:35

看起来android studio当前的1.5.1版本中有一个bug。我和你有同样的问题,但我只想把这个版本重命名为apk。

因此,我最终使用了这个快速解决方法,仅当选定的signinConfig是发行版时才重命名apk:

代码语言:javascript
运行
复制
android.applicationVariants.all { variant ->
    if (variant.buildType.signingConfig.getName() == android.signingConfigs.release.getName()) {
        variant.outputs.each { output ->
            def file = output.outputFile
            def formattedDate = new Date().format('yyyy_MM_dd_HH_mm')
            output.outputFile = new File(file.parent, file.name.replace(".apk",
                    "-" + formattedDate + ".apk"))
        }
    }
}

所有调试版本都将具有相同的名称,因此Android Studio在将其上传到设备之前刷新apk名称是否有困难也没关系

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34722304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档