更新到 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 downgrade 2.10.5
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)
我建议你将删除的代码保存在某处。
就我而言,我在项目中使用了
flutter_google_places
。我必须重写 google_api_headers
依赖项。
dependency_overrides:
google_api_headers: ^1.3.0-dev.0
我还删除了产生错误的文件中的 try-catch 部分 GoogleApiHeadersPlugin.kt
升级所有 Firebase 插件可以解决该问题。对于此答案的日期,最新版本是:
cloud_firestore to 3.1.15
firebase_auth to 3.3.18
firebase_core to 1.17.0
firebase_crashlytics to 2.8.0
firebase_messaging to 11.4.0
firebase_remote_config to 2.0.7
firebase_storage to 10.2.16
对我有用的是:
使用您的编译选项
compileOptions {
// Flag to enable support for the new language APIs
// coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
问题出在 < google_api_headers > google 包
我正在使用
google_maps_place_picker_mb: ^3.1.2
我现在正在使用
map_location_picker: ^1.3.2
并构建。现在一切正常。
谢谢你