简体   繁体   English

无法在 Flutter 中构建具有多种口味的发布 apk?

[英]Can't build release apk with multi flavors in Flutter?

I'm using Flutter (version 1.17.4) for developing Android and config multi Flavors for running multi-environment.我正在使用 Flutter(版本 1.17.4)开发 Android 并配置multi Flavors以运行多环境。

My source code has 3 environment: dev (devlopment), uat (QC), prod (Production).我的源代码有 3 个环境: dev (开发)、 uat (QC)、 prod (生产)。

Source : https://github.com/huubao2309/demo_multi_flavors Sourcehttps://github.com/huubao2309/demo_multi_flavors

My multiFlavors.gradle file ( /android/app/multiFlavors.gradle ):我的multiFlavors.gradle文件( /android/app/multiFlavors.gradle ):

android {
    flavorDimensions "app"

    productFlavors {
      prod {
        dimension "app"
        applicationIdSuffix ".prod"
        versionNameSuffix "-prod"
      }
      dev {
        dimension "app"
        applicationIdSuffix ".dev"
        versionNameSuffix "-dev"
      }
      uat {
        dimension "app"
        applicationIdSuffix ".uat"
        versionNameSuffix "-uat"
      }
   }
}

Every time, I build app for release with terminal:每次,我都会构建应用程序以使用终端发布:

flutter build apk --flavor uat -t lib/main-uat.dart

File.apk is created but terminal throws an exception: File.apk 已创建,但终端抛出异常:

Gradle build failed to produce an.apk file. It's likely that this file was generated under D:\demo_multi_flavors\build, but the tool couldn't find it.

错误

I also had this problem when running in debug mode, but on Android Studio (version 4.0), I added config build flavor , the problem is resolved:我在debug模式下运行时也遇到了这个问题,但是在 Android Studio(4.0 版)上,我添加了 config build flavor ,问题得到了解决:

添加风味

How to solve the problem with release mode?如何解决发布模式的问题?

This bug appears to be caused by Flutter looking for an exact .apk name, but not being able to find it.此错误似乎是由 Flutter 寻找确切的.apk名称,但无法找到它引起的。 In my case, the name of the.apk being generated was app-release-unsigned.apk but needed to be app-release.apk .在我的例子中,生成的 the.apk 的名称是app-release-unsigned.apk但需要是app-release.apk This was my solution:这是我的解决方案:

  buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        applicationVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "app-${variant.getName()}.apk"
            }
        }
    }
}

Reference: https://github.com/flutter/flutter/issues/44796#issuecomment-602278977参考: https://github.com/flutter/flutter/issues/44796#issuecomment-602278977

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM