Flutter。Gradle build未能生成一个.apk文件。这个文件可能是在<app_root>build下生成的,但工具无法找到它。[英] Flutter: Gradle build failed to produce an .apk file. It's likely that this file was generated under <app_root>\build, but the tool couldn't find it

本文是小编为大家收集整理的关于Flutter。Gradle build未能生成一个.apk文件。这个文件可能是在<app_root>build下生成的,但工具无法找到它。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在尝试测试一个应用程序.由于应用程序无法调试/运行,因此我一直在这个问题上遇到一个奇怪的问题. SDK版本为28,而其余的则为:

Flutter 1.13.9-pre.79 • channel master • https://github.com/flutter/flutter.git
Framework • revision 9eb9ea0ffa (6 hours ago) • 2020-01-13 21:30:42 -0800
Engine • revision 0235a50843
Tools • Dart 2.8.0 (build 2.8.0-dev.0.0 28c335d5a2)

在此处输入图像说明

Gradle Build无法生成.APK文件.这很可能 文件是在c:\ development \\ build下生成的,但是工具 找不到.

有没有办法通过此问题或可以通过提供或给出Gradle的输出路径来运行的配置? .APK似乎以错误状态生成.

Is there a way to pass this issue or a configuration that can allow me to run by providing or giving the output path to Gradle? The .apk seems to generated as the error states.

enter image description here

UPDATE:

Android Studio -v 3.5.3 
Gradle -v 3.4.2 
Gradle Wrapper -v 5.1.1

推荐答案

in my case I have a multi flavor app like this:

update 04/15/2021:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
            {
                    "name": "YOUR_PROJECT_NAME",
                    "program": "lib/main.dart",
                    "request": "launch",
                    "type": "dart",
                    "args": [
                            "--flavor",
                            "ADD_YOUR_FLAVOR_NAME_HERE" //development or staging or production
                        ]
            }
    ]

Another way:

 android {

    ...

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }

    flavorDimensions "flavor-type"

    productFlavors{
        development{
            dimension "flavor-type"
        }
        staging{
            dimension "flavor-type"
        }
        production{
            dimension "flavor-type"
        }
    }
}

So if you want to run app you have to write the flavor name and then the class name that hold main() function

flutter run --flavor staging -t lib/main_staging.dart

and I solved my error and built the .apk

其他推荐答案

Added the flavor name in Build name from Edit Configurations and it worked! enter image description here

其他推荐答案

Ok, I found that it's args in launch.json if you use vscode

enter image description here