Flutter构建apk错误:任务':app:compileFlutterBuildRelease'执行失败
Posted
技术标签:
【中文标题】Flutter构建apk错误:任务\':app:compileFlutterBuildRelease\'执行失败【英文标题】:Flutter build apk error: Execution failed for task ':app:compileFlutterBuildRelease'Flutter构建apk错误:任务':app:compileFlutterBuildRelease'执行失败 【发布时间】:2021-06-19 19:30:39 【问题描述】:我正在尝试为 google play 控制台构建一个 android apk。当我跑步时
FAILURE: Build failed with an exception.
* Where:
Script '/opt/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 991
* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command '/opt/flutter/bin/flutter'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 48s
Running Gradle task 'assembleRelease'... 49.0s
Gradle task assembleRelease failed with exit code 1
Process finished with exit code 1
有谁知道出了什么问题以及如何解决?
flutter build apk --verbose
[+4690 ms] [+5536 ms] ../../../.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.19.1/lib/src/picture_provider.dart:52:59: Error: No named parameter with
the name 'nullOk'.
[ +1 ms] [ +1 ms] context != null ? Localizations.localeOf(context, nullOk: true) : null,
[ ] [ ] ^^^^^^
[ ] [ ] /opt/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't
match.
[ ] [ ] static Locale localeOf(BuildContext context)
[ ] [ ] ^^^^^^^^
[+4399 ms] [+4424 ms] Persisting file store
[ ] [ +2 ms] Done persisting file store
[ ] [ +1 ms] Target kernel_snapshot failed: Exception
[ ] #0 KernelSnapshot.build (package:flutter_tools/src/build_system/targets/common.dart:278:7)
[ ] <asynchronous suspension>
[ ] #1 _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:796:9)
[ ] <asynchronous suspension>
[ ] #2 Future.wait.<anonymous closure> (dart:async/future.dart)
[ ] <asynchronous suspension>
[ ] #3 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:734:32)
[ ] <asynchronous suspension>
[ ] #4 Future.wait.<anonymous closure> (dart:async/future.dart)
[ ] <asynchronous suspension>
[ ] #5 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:734:32)
[ ] <asynchronous suspension>
[ +1 ms] #6 Future.wait.<anonymous closure> (dart:async/future.dart)
[ ] <asynchronous suspension>
[ ] #7 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:734:32)
[ ] <asynchronous suspension>
[ ] #8 FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:563:16)
[ ] <asynchronous suspension>
[ ] #9 AssembleCommand.runCommand (package:flutter_tools/src/commands/assemble.dart:220:32)
[ ] <asynchronous suspension>
[ ] #10 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1157:12)
[ ] <asynchronous suspension>
[ +18 ms] #11 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1009:27)
[ ] <asynchronous suspension>
[ ] #12 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[ ] <asynchronous suspension>
[ ] #13 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[ ] <asynchronous suspension>
[ ] #14 CommandRunner.runCommand (package:args/command_runner.dart:197:13)
[ ] <asynchronous suspension>
[ ] #15 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
[ ] <asynchronous suspension>
[ +1 ms] #16 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[ ] <asynchronous suspension>
[ ] #17 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[ ] <asynchronous suspension>
[ ] #18 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
[ ] <asynchronous suspension>
[ ] #19 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
[ ] <asynchronous suspension>
[ ] #20 run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
[ ] <asynchronous suspension>
[ +7 ms] #21 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[ ] <asynchronous suspension>
[ ] #22 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[ ] <asynchronous suspension>
[ ] #23 runInContext (package:flutter_tools/src/context_runner.dart:73:10)
[ ] <asynchronous suspension>
[ ] #24 main (package:flutter_tools/executable.dart:90:3)
[ ] <asynchronous suspension>
[ ] [ +3 ms]
[ ] #0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
[ ] #1 AssembleCommand.runCommand (package:flutter_tools/src/commands/assemble.dart:237:7)
[ +3 ms] <asynchronous suspension>
[ ] #2 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1157:12)
[ ] <asynchronous suspension>
[ ] #3 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1009:27)
[ ] <asynchronous suspension>
[ ] #4 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[ ] <asynchronous suspension>
[ ] #5 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[ ] <asynchronous suspension>
[ ] #6 CommandRunner.runCommand (package:args/command_runner.dart:197:13)
[ +7 ms] <asynchronous suspension>
[ ] #7 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
[ ] <asynchronous suspension>
[ ] #8 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[ ] <asynchronous suspension>
[ ] #9 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[ ] <asynchronous suspension>
[ ] #10 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
[ ] <asynchronous suspension>
[ ] #11 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
[ +5 ms] <asynchronous suspension>
[ ] #12 run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
[ ] <asynchronous suspension>
[ ] #13 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
[ ] <asynchronous suspension>
[ ] #14 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
[ ] <asynchronous suspension>
[ ] #15 runInContext (package:flutter_tools/src/context_runner.dart:73:10)
[ ] <asynchronous suspension>
[ ] #16 main (package:flutter_tools/executable.dart:90:3)
[ ] <asynchronous suspension>
[ +3 ms] FAILURE: Build failed with an exception.
[ ] * Where:
[ ] Script '/opt/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 991
[ ] * What went wrong:
[ ] Execution failed for task ':app:compileFlutterBuildRelease'.
[ ] > Process 'command '/opt/flutter/bin/flutter'' finished with non-zero exit value 1
[ ] * Try:
[ ] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full
insights.
[ ] * Get more help at https://help.gradle.org
[ ] BUILD FAILED in 56s
[ ] [ +9 ms] "flutter assemble" took 10,215ms.
[ ] [ +1 ms] ensureAnalyticsSent: 0ms
[ ] [ +1 ms] Running shutdown hooks
[ +4 ms] [ ] Shutdown hooks complete
[ ] [ +1 ms] exiting with code 1
[ ] > Task :app:compileFlutterBuildRelease FAILED
[ ] > Task :agora_rtc_engine:bundleLibCompileRelease
[ ] 28 actionable tasks: 28 executed
[ +367 ms] Running Gradle task 'assembleRelease'... (completed in 57.4s)
[ +3 ms] "flutter apk" took 57,915ms.
[ +3 ms] Gradle task assembleRelease failed with exit code 1
[ ]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1 buildGradleApp (package:flutter_tools/src/android/gradle.dart:411:7)
<asynchronous suspension>
#2 _AndroidBuilderImpl.buildApk (package:flutter_tools/src/android/android_builder.dart:101:7)
<asynchronous suspension>
#3 BuildApkCommand.runCommand (package:flutter_tools/src/commands/build_apk.dart:103:5)
<asynchronous suspension>
#4 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1157:12)
<asynchronous suspension>
#5 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1009:27)
<asynchronous suspension>
#6 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#7 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#8 CommandRunner.runCommand (package:args/command_runner.dart:197:13)
<asynchronous suspension>
#9 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
<asynchronous suspension>
#10 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#11 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#12 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
<asynchronous suspension>
#13 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
<asynchronous suspension>
#14 run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
<asynchronous suspension>
#15 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#16 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#17 runInContext (package:flutter_tools/src/context_runner.dart:73:10)
<asynchronous suspension>
#18 main (package:flutter_tools/executable.dart:90:3)
<asynchronous suspension>
[ +166 ms] ensureAnalyticsSent: 154ms
[ +1 ms] Running shutdown hooks
[ ] Shutdown hooks complete
[ ] exiting with code 1
在我将flutter_svg
升级到^0.20.0-nullsafety.3
之后
[ +3 ms] Gradle task assembleRelease failed with exit code 1
[ ]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1 buildGradleApp (package:flutter_tools/src/android/gradle.dart:411:7)
<asynchronous suspension>
#2 _AndroidBuilderImpl.buildApk
(package:flutter_tools/src/android/android_builder.dart:101:7)
<asynchronous suspension>
#3 BuildApkCommand.runCommand (package:flutter_tools/src/commands/build_apk.dart:103:5)
<asynchronous suspension>
#4 FlutterCommand.verifyThenRunCommand
(package:flutter_tools/src/runner/flutter_command.dart:1157:12)
<asynchronous suspension>
#5 FlutterCommand.run.<anonymous closure>
(package:flutter_tools/src/runner/flutter_command.dart:1009:27)
<asynchronous suspension>
#6 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#7 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#8 CommandRunner.runCommand (package:args/command_runner.dart:197:13)
<asynchronous suspension>
#9 FlutterCommandRunner.runCommand.<anonymous closure>
(package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
<asynchronous suspension>
#10 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#11 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#12 FlutterCommandRunner.runCommand
(package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
<asynchronous suspension>
#13 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
<asynchronous suspension>
#14 run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
<asynchronous suspension>
#15 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#16 AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
<asynchronous suspension>
#17 runInContext (package:flutter_tools/src/context_runner.dart:73:10)
<asynchronous suspension>
#18 main (package:flutter_tools/executable.dart:90:3)
<asynchronous suspension>
【问题讨论】:
【参考方案1】:1- 你用的是什么 Flutter 的渠道,稳定吗?
2- 如果没有,请切换到 stable 并运行 flutter upgrade
。
3- 然后运行flutter clean
。
4- 确保您在项目的终端中处于正确的路径中。
5- 然后flutter build apk
。
如果失败,请提供此命令的输出flutter build apk --verbose
这将详细解释失败的原因和位置,并报告。
-=-=- 编辑 1,在 OP 发布 flutter build apk --verbose
的输出后
读取输出的前三行,有你的错误
context != null ? Localizations.localeOf(context, nullOk: true) : null,
[ ] [ ] ^^^^^^ [ ] [ ]
opt/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17:
Context: Found this candidate, but the arguments don't match.
[ ] [ ] static Locale localeOf(BuildContext context)
[ ] [ ] ^^^^^^^^
这 ==> nullOk:true
发布与您的 SVG 包相关的代码,告诉您的应用它不会为空,但它正在接收空值。
尝试在 pubspec.yaml 中更新你的 flutter_svg 包到这个版本
flutter_svg: ^0.20.0-nullsafety.3
【讨论】:
我已经运行升级并且我处于稳定状态。正确的路径是什么意思? 我提到了6个步骤,请不要停留在#2。路径,我的意思是你的项目的路径。即user/halfengZhangdesktop/myAppProject/
这就是路径,您的项目是否在正确的路径中?你的路径是什么,运行构建时终端中的路径是什么?
我已经尝试了这些步骤,但错误仍然存在。
老兄,flutter build apk --verbose
的输出是什么。显然有什么问题发生了,这不是一个猜谜游戏,你只会回答“它不起作用”。我们知道它显然不起作用,我们正在尝试调试它,这个命令的输出是什么?
我更新了答案,你应该将 svg 包更新到版本:flutter_svg: ^0.20.0-nullsafety.3
【参考方案2】:
这个错误有两种解决方法
您需要按此顺序构建,否则发布构建会抱怨缺少 debug.jars 或 profile.jars
我。 flutter build apk --debug
二。 flutter build apk --profile
三。 flutter build apk --release
2) 降级gradle.build
dependencies
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
到
dependencies
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
还改了gradle-warpper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
到
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
注意:lintOptions checkReleaseBuilds false
有时也可以查看此问题以获取更多详细信息
':app:lintVitalRelease' error when generating signed apk
【讨论】:
感谢您的回复。我的 build.gradle 和 gradle-warpper.properties 和你的降级版本一样以上是关于Flutter构建apk错误:任务':app:compileFlutterBuildRelease'执行失败的主要内容,如果未能解决你的问题,请参考以下文章
Flutter App Build apk报错但运行正确解决
任务':app:mergeDebugResources'的Flutter构建失败