3
votes

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: 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 Session 'app': Error Installing APK

Here is my build.gradle file:

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 {
    // ...
}

So is there any wrong with releaseTime()?

7
Yes, do you see the exact times? One is 11:30:14. the other one is 11:30:29 (which is what you found but different from what the computer expects)ucsunil
@ucsunil Thanks for your reply. I noticed the difference between the two times, but I have no idea on solving it :( I don't know how does gradle find the apk.RockerFlower
Suggest to use git date instead: ex. "git show -s --format=%ci" and more here: github.com/JakeWharton/u2020/blob/master/build.gradle about pretty format : git-scm.com/docs/pretty-formatsNevin Chen

7 Answers

15
votes

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.

3
votes

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
votes

This happened on me because I removed all the "Extras" tools under "Standalone SDK Manager" and re-download the necessary tools only. *I'm not sure is this related to the problem or not.

Anyway I tried both Sync Gradle and Rebuild Project doesn't solve the problems.

EmptyThrowable: The APK file D:\...\outputs\apk\app-debug.apk does not exist on disk.

I solved it by clicked:

Build > Build APK

Working solution for me.

2
votes

I have tried all the things like

  • Delete folders app/apks and app//build/outputs/apk previously
  • SyncGradle and Rebuild Project
  • lintOptions { abortOnError false }

but got issue resolved by Clicking on Build>Build APK

enter image description here

2
votes

I had the same issue and nothing suggested above helped: neither clean/build nor restart Android Studio/PC. The problem was that there was locked file .gradle/buildOutputCleanup/cache.properties. Just removing cache.properties.LOCK file and then cleaning the project fixes the issue

1
votes

The reason is because Gradle is calculating the time twice - once when building the apk, then again while trying to install it.

Do not calculate time again when you are creating the endFileName. Just do:

def endFileName = time + "_${variant.productFlavors[0].name}.apk"
0
votes

Restarting Android Studio worked for me. Hopefully same will work for you. Else have a look at below link. The APK file does not exist on disk

Edit- If this doesn't work , use Invalidate Cache / Restart in File menu. Hope this helps.