EmptyThrowable:磁盘

时间:2016-02-22 03:57:20

标签: android gradle android-gradle

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

  

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:32会话'app':安装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()是否有任何问题?

7 个答案:

答案 0 :(得分:15)

在我的情况下,问题是要安装的apk的名称是缓存的,所以每次我尝试运行应用程序时,都会生成一个带有今天日期的apk,但在安装时,Android Studio查找了一个apk具有旧名称的文件。解决方案是单击 Sync Gradle ,然后单击 Build > 重建项目。您可能还想先删除文件夹 app / apks app // build / outputs / apk

答案 1 :(得分:3)

In my case it was a problem for the android plugin version. i changed it from File->Project Structure->Project and changed the Android Plugin Version to any previous version. it may be any version of Android Studio. Basically Android Plugin Version is the version of your Android Studio Software version. It's not mandatory to keep the android plugin version same as android studio software version. you can give it any previous version of android studio you have installed.

答案 2 :(得分:2)

这发生在我身上,因为我删除了“Standalone SDK Manager”下的所有“Extras”工具,并仅重新下载了必要的工具。 *我不确定这是否与问题有关。

无论如何,我尝试了 Sync Gradle Rebuild Project 并没有解决问题。

  

EmptyThrowable :磁盘上不存在APK文件D:\ ... \ outputs \ apk \ app-debug.apk。

我点击了解决了它:

  

构建>构建APK

为我工作的解决方案。

答案 3 :(得分:2)

我尝试了所有的事情,比如

  • 先删除文件夹app / apks和app // build / outputs / apk
  • SyncGradle和Rebuild Project
  • lintOptions {             abortOnError为false         }

但点击了构建>构建APK

,解决了问题

enter image description here

答案 4 :(得分:2)

我遇到了同样的问题,上面没有任何建议有帮助:既不清理/构建也不重启Android Studio / PC。问题是存在锁定文件.gradle / buildOutputCleanup / cache.properties。只需删除cache.properties.LOCK文件然后清理项目就可以解决问题

答案 5 :(得分:1)

原因是因为Gradle计算时间两次 - 一次在构建apk时,然后在尝试安装时再次计算。

创建endFileName时不要再计算时间。只是做:

{{1}}

答案 6 :(得分:0)

重启Android Studio对我有用。希望同样适合你。 另外请看下面的链接。 The APK file does not exist on disk

编辑 - 如果这不起作用,请在“文件”菜单中使用“无效缓存/重新启动”。希望这会有所帮助。

相关问题