gpt4 book ai didi

firebase - 任务 ':app:transformClassesAndResourcesWithR8ForRelease' 执行失败。在尝试获取 flutter 应用程序的 apk 时

转载 作者:行者123 更新时间:2023-12-05 06:17:23 24 4
gpt4 key购买 nike

我尝试使用

获取我的 flutter 应用程序的 APK

flutter build APK

但是它返回了这个错误。我不知道这是什么意思。如果你想帮助我,我会很高兴。如果您需要任何额外的详细信息来解决错误,请在这篇文章中发表评论

Running Gradle task 'assembleRelease'... R8: Type com.google.firebase.iid.zzbb is referenced as an interface from com.google.firebase.messaging.zzf.

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease'. com.android.tools.r8.CompilationFailedException: Compilation failed to complete

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run wit h --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 7m 32s Running Gradle task 'assembleRelease'... Running Gradle task 'assembleRelease'... Done 456.4s (!) [!] The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the --no-shrink flag to this command. To learn more, see: https://developer.android.com/studio/build/shrink-code Gradle task assembleRelease failed with exit code 1

最佳答案

我回答这个问题是因为这是我搜索错误消息时得到的第一批结果之一。

我有同样的错误。 R8结果证明是二进制 java 文件的“收缩器”,它掩盖了错误背后的问题。在 gradle.properties 中,我将 android.enableR8true 更改为 false 然后重建 apk。我得到了一个不同的错误:

...
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkReleaseDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.4.0-runtime.jar (androidx.lifecycle:lifecycle-viewmodel:2.4.0) and lifecycle-viewmodel-ktx-2.2.0-runtime.jar (androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0)
Duplicate class androidx.lifecycle.ViewModelProviderKt found in modules lifecycle-viewmodel-2.4.0-runtime.jar (androidx.lifecycle:lifecycle-viewmodel:2.4.0) and lifecycle-viewmodel-ktx-2.2.0-runtime.jar (androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0)

Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
...

错误是因为我有两个版本的生命周期 View 模型运行时:2.2.0 和 2.4.0。我搜索了项目和插件,结果只有一个使用V2.4.0,其余的都使用V2.2.0:

    def lifecycle_version = "2.4.0"
def arch_version = "2.1.0"

// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"

我刚刚将 lifecycle_version 更改为 2.2.0 并且我能够正确构建 apk。

不要忘记将 android.enableR8 设置回 true

关于firebase - 任务 ':app:transformClassesAndResourcesWithR8ForRelease' 执行失败。在尝试获取 flutter 应用程序的 apk 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61696533/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com