The APK file does not exist on disk
来源:互联网 发布:义乌最好的淘宝摄影 编辑:程序博客网 时间:2024/06/07 20:09
背景
如果你使用Android studio 遇到这个问题,那么一般你是想对编译时生成的apk文件进行自定义命名,并且你的命名规则包含动态部分,比如,命名规则中使用了时间戳。由于gradle在执行编译命令和安装命令时有时间差,且调用了两次你的名称规则,导致编译出来的apk名称和安装时获取到的apk名称不一致,所以它就报找不到指定的apk文件了。
场景
一般修改编译后apk文件名,在gradle是这样配置的
android { applicationVariants.all{variant-> variant.outputs.each{output-> if(variant.buildType.name.equals('release')) { def oldFile = output.outputFile def newName = 'dayjoke_V'+defaultConfig.versionName+'_'+getDate()+'-release.apk'; output.outputFile = new File(oldFile.parent, newName) } } }}def getDate() { def date = new Date() def formattedDate = date.format('yyyy_MM_dd_HH_mm_ss') return formattedDate}
但是这种命名规则是到秒级的,所以每次构建和安装时获取的文件名称都不一样,每次都会报错。
解决方案
- 遇到这个问题时,首先想到的是,如何让编译出来的apk文件名和要安装的文件名相同,而gradle 执行安装的task是installRelease,那么就是如何动态修改installRelease 命令中指定安装的文件名。虽然这是一个方向,但是我并不会耶没有找到修改的方法。最简单的办法就是固定apk的文件名,至少不要使用时间戳这种容易改变的命名规则。
- 后来找到另一种解决办法,可以使得照样使用时间戳来命名apk文件,配置如下:
android { applicationVariants.all{variant-> variant.outputs.each{output-> if(variant.buildType.name.equals('release')) { def oldFile = output.packageApplication.outputFile def newName = 'dayjoke_V'+defaultConfig.versionName+'_'+getDate()+'-release.apk'; output.packageApplication.outputFile = new File(oldFile.parent, newName) } } }}def getDate() { def date = new Date() def formattedDate = date.format('yyyy_MM_dd_HH_mm_ss') return formattedDate}
不同之处在于outputFile
output.outputFile
和
output.packageApplication.outputFile
通过编译执行比较,发现,前者即用来编译出apk文件,也用于安装;而后者,只是编译出apk文件。如下图:
使用output.packageApplication.outputFile
使用output.outputFile
0 0
- Android Studio The APK file does not exist on disk
- The APK file **** does not exist on disk
- Android Studio The APK file does not exist on disk
- The APK file does not exist on disk
- EmptyThrowable: The APK file does not exist on disk.
- The APK file does not exist on disk
- The APK file does not exist on disk
- Launching app : The APK file xxxx.apk does not exist on disk Error while Installing APK
- The APK file xxx.apk does not exist on disk. Error while Installing APK
- The APK file xxx.apk does not exist on disk. Error while Installing APK
- The APK file D:\Code\Air\app\build\outputs\apk\.apk does not exist on disk.
- The APK file does not exist on disk.Error while Installing APK
- The APK file does not exist on disk.Error while Installing APK
- Android Studio编译后安装apk报错:The APK file does not exist on disk
- The APK file app-debug.apk does not exist on disk.
- the apk file does not exist on disk. error while installing apk
- Android Studio编译后安装apk报错:The APK file does not exist on disk
- APK file does not exist on disk问题解决
- js常见事件及案例-onSubmit
- Android 异步网络请求导致的程序崩溃
- 文件拷贝速度比较
- 3d基础图形原理
- phaser.js显示对象篇
- The APK file does not exist on disk
- spring整合mybatis
- Retrofit2 使用经验
- Helper2416开发板移植minigui3.0.12之二:移植到开发板
- 友元 成员 非成员 点间距离
- 13. php数据库抽象层PDO(二)
- 防止机器注册
- rabbitmq中消息的存储
- jQ源码之camelCase