Gradle 构建无法生成 .apk 文件
Posted
技术标签:
【中文标题】Gradle 构建无法生成 .apk 文件【英文标题】:Gradle build failed to produce an .apk file 【发布时间】:2020-04-13 23:43:12 【问题描述】:将 Flutter 从 1.9.7 升级到 v1.12.13+hotfix.5 后,我的应用程序构建失败。我遇到了以下异常:
[ +124 ms] > Task :draw:compileFossDebugSources UP-TO-DATE
[ +5 ms] > Task :draw:assembleFossDebug UP-TO-DATE
[ +136 ms] Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
[ ] Use '--warning-mode all' to show the individual deprecation warnings.
[ ] See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
[ ] BUILD SUCCESSFUL in 5m 30s
[ ] 396 actionable tasks: 16 executed, 380 up-to-date
[ +529 ms] Running Gradle task 'assembleFossDebug'... (completed in 331.1s, longer than expected)
[ +35 ms] "flutter run" took 332,133ms.
Gradle build failed to produce an .apk file. It's likely that this file was generated under C:\flutter_projects\my_branch\iamflexi_app\build, but the tool couldn't find it.
#0 throwToolExit (package:flutter_tools/src/base/common.dart:28:3)
#1 _exitWithExpectedFileNotFound (package:flutter_tools/src/android/gradle.dart:827:3)
#2 findApkFiles (package:flutter_tools/src/android/gradle.dart:765:5)
#3 buildGradleApp (package:flutter_tools/src/android/gradle.dart:451:35)
#4 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:73:64)
#5 _rootRunUnary (dart:async/zone.dart:1134:38)
#6 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#7 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
#8 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
#9 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
#10 Future._completeWithValue (dart:async/future_impl.dart:524:5)
#11 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:32:15)
#12 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:290:13)
#13 _DefaultProcessUtils.stream (package:flutter_tools/src/base/process.dart)
#14 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:73:64)
#15 _rootRunUnary (dart:async/zone.dart:1134:38)
#16 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#17 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
#18 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
#19 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
#20 Future._completeWithValue (dart:async/future_impl.dart:524:5)
#21 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:554:7)
#22 _rootRun (dart:async/zone.dart:1126:13)
#23 _CustomZone.run (dart:async/zone.dart:1023:19)
#24 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#25 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
#26 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#27 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#28 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#29 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:175:5)
但是,当我在 Android Studio 中的 Android 模块中打开我的应用程序时,它运行良好,但是当我尝试使用 Flutter 运行时,出现了该错误。
【问题讨论】:
你已经升级到 gradle 6 与其他人不匹配。要查看已弃用的内容,请使用:***.com/questions/51610420/… 如果你愿意,你也可以降级 gradle 版本 distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 这是我在 gradle-wrapper.properties 文件中的 gradle 版本,它在Flutter 1.9.7 版,但在我升级到 Flutter 1.12 版后,我收到了这个错误。 我不知道为什么,但看看:***.com/a/59453116/6658129 看到这个答案***.com/a/61347715/11675817 【参考方案1】:使用 Android Studio 可能会提示您升级项目的设置(即 gradle 版本)。此问题的快速解决方法是降级到项目以前的 gradle 版本,如之前在 cmets 中提到的。您还可以尝试查看此 GitHub 问题线程 ahttps://github.com/flutter/flutter/issues/45681 上发布的建议,看看是否有任何适合您的方法。
【讨论】:
以上是关于Gradle 构建无法生成 .apk 文件的主要内容,如果未能解决你的问题,请参考以下文章
无法从 Java 源使用最新的 gradle 构建工具 (3.6.3) 生成 APK,错误引用 Kotlin
Android Gradle 构建生成的 apk 包含混淆和非混淆类
Gradle 构建完成,出现 520 个错误,但 APK 生成成功
在构建 gradle 和提交中更改版本代码后,不使用 devops Pipeline 生成 Android APK 版本明智