当我尝试在Android Studio上调试应用程序时,给出了以下日志输出:

APK文件 /Users/MyApplicationName/app/build/outputs/apk/app-debug.apk没有 存在于磁盘上。

我重启了Android Studio,但是我无法解决这个问题。我怎么解决呢? 谢谢你!


当前回答

当我切换git分支时,我经常看到类似的问题。对我来说,关闭AndroidStudio rm -rfv ~/Library/Caches/AndroidStudio*并重新启动AndroidStudio是门票。

其他回答

我的问题是我将版本号附加到APK。更改版本号和重新同步Gradle为我解决了这个问题。

def appendVersionNameVersionCode(variant, defaultConfig) {
    variant.outputs.each { output ->
        if (output.zipAlign) {
            def file = output.outputFile
            def removeApp = file.name.replace("app-", "")
            def removeType = removeApp.replace("-release", "")
            def fileName = removeType.replace(".apk", "." + defaultConfig.versionName + ".apk")
            output.outputFile = new File(file.parent, fileName)
        }

        def file = output.packageApplication.outputFile
        def removeApp = file.name.replace("app-", "")
        def removeType = removeApp.replace("-release", "")
        def fileName = removeType.replace(".apk", "." + defaultConfig.versionName + ".apk")
        output.packageApplication.outputFile = new File(file.parent, fileName)
    }
}

在我的例子中,我在应用程序文件路径中使用了一个特殊字符。我关闭了Android Studio并从我的应用程序文件路径中删除了'字符。当我重新启动项目时,一切都很正常。

删除~/.gradle/caches/目录。在Android Studio打开时这样做是可以的。(参考pm安装错误的包名) 在Android Studio上按“同步项目与Gradle文件”图标 运行项目,远程路径将是正确的。

参考答案@ Android Studio在运行.apk时得到错误的包名

在Android Studio 3.1.1中选择文件|同步项目与Gradle文件。

在Android Studio 3中,选择“文件|同步”。

然后再次运行您的项目。

通过更新Android SDK-Build Tools解决了这个问题。