尝试使用风味时 Flutter 应用程序构建失败
Flutter app build fails when trying to use flavors
我正在尝试在我的应用程序中使用 Flavors。我遵循了各种指南,但每次都因同样的问题而无法构建。 (因为基本上每个博客 post 和 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
)的“开发”风格时,它会构建 运行s。
运行 --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 添加到开发风格时,同样的问题出现了,正如我所说,标准 flutter 示例项目不存在这个问题(事实上,简单项目的测试结果允许我设置字符串资源和启动器图标在每个口味的基础上成功)
答案已经盯着我看了一整天了。
如果您更改 applicationId,则需要一个新的 google-services.json 文件。
解决方案是为每个 "Flavor" 或更具体地为每个 applicationId 生成文件,并将它们包含到应用程序资源中。
这里有一个关于如何做到这一点的很好的答案:
只需卸载应用程序并重新安装,它对我有用。
我正在尝试在我的应用程序中使用 Flavors。我遵循了各种指南,但每次都因同样的问题而无法构建。 (因为基本上每个博客 post 和 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
)的“开发”风格时,它会构建 运行s。
运行 --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 添加到开发风格时,同样的问题出现了,正如我所说,标准 flutter 示例项目不存在这个问题(事实上,简单项目的测试结果允许我设置字符串资源和启动器图标在每个口味的基础上成功)
答案已经盯着我看了一整天了。
如果您更改 applicationId,则需要一个新的 google-services.json 文件。
解决方案是为每个 "Flavor" 或更具体地为每个 applicationId 生成文件,并将它们包含到应用程序资源中。
这里有一个关于如何做到这一点的很好的答案:
只需卸载应用程序并重新安装,它对我有用。