EmptyThrowable:磁盘上不存在 APK 文件 *.apk

EmptyThrowable: The APK file *.apk does not exist on disk(EmptyThrowable:磁盘上不存在 APK 文件 *.apk)
本文介绍了EmptyThrowable:磁盘上不存在 APK 文件 *.apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

这是一个使用 gradle 的 Android 应用程序.点击运行后,发现APP_V1.3.4_2016-02-22_11:30:29outputs/apk 中的 _google_play.apk,但事件日志显示:

This is an Android application using gradle. After clicking Run, I found APP_V1.3.4_2016-02-22_11:30:29_google_play.apk in outputs/apk, but the event log says:

11:30:31 EmptyThrowable:APK 文件/.../WorkSpace/Android/.../app/build/outputs/apk/APP_V1.3.4_2016-02-22_11:30:14_google_play.apk 在磁盘上不存在.

11:30:31 EmptyThrowable: The APK file /.../WorkSpace/Android/.../app/build/outputs/apk/APP_V1.3.4_2016-02-22_11:30:14_google_play.apk does not exist on disk.

11:30:32 会话应用程序":安装 APK 时出错

11:30:32 Session 'app': Error Installing APK

这是我的 build.gradle 文件:

apply plugin: 'com.android.application'

def releaseTime() {
    return new Date().format("yyyy-MM-dd_HH:mm:ss",
        TimeZone.getTimeZone("GMT+08:00"))
}

android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 29
        versionName "1.3.4"
        manifestPlaceholders = [SOME_CHANNEL_VALUE: "some_channel"]
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    signingConfigs {
        debug {}

        release {
            // ...
        }
    }

    buildTypes {
        debug {
            zipAlignEnabled true
            minifyEnabled false
            shrinkResources true
        }

        release {
            zipAlignEnabled true
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                'proguard-rules.pro'
            signingConfig signingConfigs.release

            applicationVariants.all { variant ->

                def time = releaseTime()

                variant.outputs.each { output ->
                    def apk = output.outputFile
                    def endFileName = "${time}_${variant.productFlavors[0].name}.apk"

                    if (apk != null &&
                        apk.name.endsWith('.apk') &&
                        !apk.name.endsWith('${endFileName}')) {
                        def fileName = "APP_V${defaultConfig.versionName}_${endFileName}"
                        output.outputFile = new File(apk.parentFile, fileName)
                    }
                }
            }
        }
    }

    productFlavors {
        google_play {
            manifestPlaceholders = [SOME_CHANNEL_VALUE: "google_play"]
        }
    }
}

dependencies {
    // ...
}

那么releaseTime()有什么问题吗?

推荐答案

在我的情况下,问题是要安装的 apk 的名称被缓存了,所以每次我尝试运行应用程序时,都会生成一个带有今天日期的 apk但是在安装时,Android Studio 会寻找一个旧名称的 apk 文件.解决方案是点击Sync Gradle,然后点击Build > Rebuild Project.您可能还想删除文件夹 app/apksapp//build/outputs/apk 之前.

In my case the problem was that the name of the apk to be installed was cached, so everytime I tried running the app, an apk with today's date was generated but when installing, Android Studio looked for an apk file with an old name. The solution was to click Sync Gradle and then Build > Rebuild Project. You may also want to delete folders app/apks and app//build/outputs/apk previously.

这篇关于EmptyThrowable:磁盘上不存在 APK 文件 *.apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)