Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

android - EmptyThrowable: The APK file *.apk does not exist on disk

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()?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...