android - 任务 ':google_api_headers:compileDebugKotlin' 执行失败

标签 android flutter dart

更新到 Dart 3.0 后,当我在 Android 模拟器上启动应用程序时出现此错误。
对于 iOS 物理设备,它的构建还可以。不幸的是,无法尝试使用 Android 物理设备。有任何想法吗?

e: /Users/amarchuk/.pub-cache/hosted/pub.dartlang.org/google_api_headers-1.2.0+1/android/src/main/kotlin/io/github/zeshuaro/google_api_headers/GoogleApiHeadersPlugin.kt: (52, 68): Type mismatch: inferred type is String? but String was expected
e: /Users/amarchuk/.pub-cache/hosted/pub.dartlang.org/google_api_headers-1.2.0+1/android/src/main/kotlin/io/github/zeshuaro/google_api_headers/GoogleApiHeadersPlugin.kt: (58, 68): Type mismatch: inferred type is String? but String was expected

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':google_api_headers:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* 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.
2

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

BUILD FAILED in 33s
Exception: Gradle task assembleDebug failed with exit code 1
Exited

最佳答案

作为临时解决方案

  • 从 Flutter 3.0 降级
  •     flutter downgrade 2.10.5
    
  • 打开产生错误 GoogleApiHeadersPlugin.kt 的文件(cmd + 在 macOS 的控制台中单击它)
    并剪掉所有的 try catch 部分
  •     try {
                    val info: PackageInfo
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
                        info = context!!.packageManager.getPackageInfo(call.arguments<String>(), PackageManager.GET_SIGNING_CERTIFICATES)
                        for (signature in info.signingInfo.apkContentsSigners) {
                            parseSignature(signature, result)
                        }
                    } else {
                        @Suppress("DEPRECATION")
                        info = context!!.packageManager.getPackageInfo(call.arguments<String>(), PackageManager.GET_SIGNATURES)
                        @Suppress("DEPRECATION")
                        for (signature in info.signatures) {
                            parseSignature(signature, result)
                        }
                    }
    
                } catch (e: Exception) {
                    result.error("ERROR", e.toString(), null)
                }
    
    所以如果方法是空的并且什么都不做
    if (call.method == "getSigningCertSha1") {}
    
    我没有足够的知识来说明这样做的后果是什么,但我的应用程序正在运行,并且所有谷歌 API 也在运行(谷歌地图、谷歌登录、Firebase)
    我建议您将已删除的代码保存在某处。

    关于android - 任务 ':google_api_headers:compileDebugKotlin' 执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72221920/

    相关文章:

    android - 在 R.attr 中找到正确的样式

    android - 如何在 flutter 中从 UST 获取本地时间

    listview - 来自父级的 Flutter 更新 ListView

    dart - 如何判断 HttpResponse 是否已关闭?

    java - 如何将 View 添加到livedata观察器内的cardview

    Android onLayout() 和 AsyncTask() 不能一起工作

    java - 在 Android 中使用 openCSV 导出 CSV

    flutter - 如何在 flutter 中更改显示日期选择器的语言

    validation - 表单验证错误消息未完全显示-Flutter

    mysql - 如何使用 PHP Mysql rest api 创建 Flutter 聊天应用程序?