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

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

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


当前回答

这个按钮叫做“同步项目与Gradle文件”,它看起来像:…当更新版本号时,总是需要单击它,这将导致另一个APK文件名(除非文件名没有改变,安装包总是有效的,这提示,文件名正在被缓存)。等效的Gradle CLI选项似乎是——recompile-scripts。

见附录D. Gradle命令行。

其他回答

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

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

然后再次运行您的项目。

我的问题是在文件名中包含分钟-它寻找appname_debug_0.9.0.1 1_170214_2216.apk,而生成的文件是appname_debug_0.9.0.1 1_170214_2217.apk,因此输出文件名代码(从其他地方捕获)显然是从构建中的两个不同的点调用的。

applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def project = "appname"
            def SEP = "_"
    //        def flavor = variant.productFlavors[0].name
            def buildType = variant.variantData.variantConfiguration.buildType.name
            def version = variant.versionName
            def date = new Date();
            def formattedDate = date.format('yyMMdd_HHmm')

            def newApkName = project + SEP + /*flavor + */ SEP + buildType + SEP + version + SEP + formattedDate + ".apk"

            output.outputFile = new File(output.outputFile.parent, newApkName)
        }
    }

构建APK(s),并确保它工作

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

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

    1) This problem occure due to apk file .if your apk file
        (output/apk/debug.apk) not generated in this format . 

    2) you should use always in gradle file .

    buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }