4

我正在尝试在我的应用程序中使用 Flavors。我遵循了各种指南,但每次都无法构建相同的问题。(因为基本上每个博客文章和 SE 问题都引用了相同的文章和资源,我不会再这样做了)

为了调试,我决定简化问题并开始一个新项目(普通示例项目),并添加每个风味只有一个元素的风味:应用程序。这行得通。其他各种更复杂的属性,例如使用 res/values/strings.xml 作为应用程序标签也可以正常工作。

然后,我使用我的应用程序尝试了最简单的风味设置,使用如下所示的grade.build,然后立即失败并出现相同的错误。

flavorDimensions "app"
productFlavors {
    dev {
        dimension "app"
    }
    qa {
        dimension "app"
        applicationId "com.example.app1"
    }
}

注意:我还使用单独的入口点来实现运行时配置。这按预期工作,并且已经使用了一段时间。

johan@komp:~/AndroidStudioProjects/parent_lite$ flutter run --flavor qa -t lib/main-qa.dart
Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main-qa.dart on Android SDK built for x86 in debug mode...
Initializing gradle...                                              0.4s
Resolving dependencies...                                           1.2s
Running Gradle task 'assembleQaDebug'...                                
Running Gradle task 'assembleQaDebug'... Done                       1.1s
Gradle task assembleQaDebug failed with exit code 1

当启动不包含任何自定义属性(通过flutter run --flavor dev -t lib/main-dev.dart)的“开发”风格时,它会构建并运行。

使用 --verbose 运行的有趣部分如下

[ +317 ms] Running Gradle task 'assembleQaDebug'... (completed in 1.1s)
[   +2 ms] "flutter run" took 3,055ms.
[        ] "flutter run" took 3,055ms.
Gradle task assembleQaDebug failed with exit code 1

#0      throwToolExit (package:flutter_tools/src/base/common.dart:28:3)
#1      _buildGradleProjectV2 (package:flutter_tools/src/android/gradle.dart:507:5)
<asynchronous suspension>
#2      buildGradleProject (package:flutter_tools/src/android/gradle.dart:346:14)
<asynchronous suspension>
#3      buildApk (package:flutter_tools/src/android/apk.dart:34:9)
<asynchronous suspension>
#4      AndroidDevice.startApp (package:flutter_tools/src/android/android_device.dart:426:13)
<asynchronous suspension>
#5      FlutterDevice.runHot (package:flutter_tools/src/resident_runner.dart:371:54)
<asynchronous suspension>
#6      HotRunner.run (package:flutter_tools/src/run_hot.dart:251:39)
<asynchronous suspension>
#7      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:469:37)
<asynchronous suspension>
#8      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:478:18)
<asynchronous suspension>
#9      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:383:33)
<asynchronous suspension>
#10     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:29)
<asynchronous suspension>
#11     _rootRun (dart:async/zone.dart:1124:13)
#12     _CustomZone.run (dart:async/zone.dart:1021:19)
#13     _runZoned (dart:async/zone.dart:1516:10)
#14     runZoned (dart:async/zone.dart:1463:12)
#15     AppContext.run (package:flutter_tools/src/base/context.dart:152:18)
<asynchronous suspension>
#16     FlutterCommand.run (package:flutter_tools/src/runner/flutter_command.dart:375:20)
#17     CommandRunner.runCommand (package:args/command_runner.dart:197:27)
<asynchronous suspension>
#18     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:396:21)
<asynchronous suspension>
#19     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:29)
<asynchronous suspension>
#20     _rootRun (dart:async/zone.dart:1124:13)
#21     _CustomZone.run (dart:async/zone.dart:1021:19)
#22     _runZoned (dart:async/zone.dart:1516:10)
#23     runZoned (dart:async/zone.dart:1463:12)
#24     AppContext.run (package:flutter_tools/src/base/context.dart:152:18)
<asynchronous suspension>
#25     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:356:19)
<asynchronous suspension>
#26     CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:112:25)
#27     new Future.sync (dart:async/future.dart:224:31)
#28     CommandRunner.run (package:args/command_runner.dart:112:14)
#29     FlutterCommandRunner.run (package:flutter_tools/src/runner/flutter_command_runner.dart:242:18)
#30     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:22)
<asynchronous suspension>
#31     _rootRun (dart:async/zone.dart:1124:13)
#32     _CustomZone.run (dart:async/zone.dart:1021:19)
#33     _runZoned (dart:async/zone.dart:1516:10)
#34     runZoned (dart:async/zone.dart:1500:12)
#35     run.<anonymous closure> (package:flutter_tools/runner.dart:60:18)
<asynchronous suspension>
#36     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:29)
<asynchronous suspension>
#37     _rootRun (dart:async/zone.dart:1124:13)
#38     _CustomZone.run (dart:async/zone.dart:1021:19)
#39     _runZoned (dart:async/zone.dart:1516:10)
#40     runZoned (dart:async/zone.dart:1463:12)
#41     AppContext.run (package:flutter_tools/src/base/context.dart:152:18)
<asynchronous suspension>
#42     runInContext (package:flutter_tools/src/context_runner.dart:56:24)
<asynchronous suspension>
#43     run (package:flutter_tools/runner.dart:51:10)
#44     main (package:flutter_tools/executable.dart:62:9)
<asynchronous suspension>
#45     main (file:///home/johan/dev/flutter/packages/flutter_tools/bin/flutter_tools.dart:8:3)
#46     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#47     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

请注意,如果我从“qa”风格中删除 applicationID,它就会构建。此外,当我将 applicationId 添加到 dev 风格时,同样的问题出现了,正如我所说,标准颤振示例项目不存在这个问题(事实上,简单项目的测试结果允许我设置字符串资源和每种口味的启动器图标成功)

4

2 回答 2

4

答案一直盯着我一整天。

如果您更改 applicationId,您需要一个新的 google-services.json 文件。

解决方案是为每个“Flavor”生成文件,或者更具体地说,为每个 applicationId 生成文件,并将这些文件包含到应用程序资源中。

这是有关如何执行此操作的一个很好的答案: https ://stackoverflow.com/a/34364376/1810447

于 2019-09-10T19:06:16.293 回答
0

只需卸载应用程序并重新安装,它对我有用。

于 2021-11-30T02:13:42.033 回答