我正在尝试在我的应用中使用Flavors。我遵循了各种指南,但每次都遇到相同的构建问题(由于实际上每篇博客文章和SE问题都引用了相同的文章和资源,我不会再重复说明)。
为了调试,我决定简化问题,并开始了一个新项目(普通样例项目),并添加了只有一个元素的各种口味:应用程序。这起作用了。各种其他更复杂的属性,例如将res/values/strings.xml用于应用程序标签,也运行良好。
然后我尝试使用最简单的Flavor设置来构建我的应用程序,根据以下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
启动不包含任何自定义属性的“dev”构建时,它会进行构建和运行。
使用--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 flavor中,相同的问题就会出现,正如我所说,这个问题在标准的flutter示例项目中不存在(实际上,使用简单的项目进行测试的结果使我能够成功地在每个flavor基础上设置字符串资源和启动器图标)。