'What went wrong: Execution failed for task ':google_api_headers:compileDebugKotlin'

When updating my flutter to version 3.0.0 , the console started showing me this error

does anyone know how to fix it

AppData\Local\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'.



Solution 1:[1]

As a temporarily solution:-

Solution 1

Delete every line of code in GoogleApiHeadersPlugin.kt file and leave it blank, then add this flutter dependency

google_api_headers: ^1.3.0

Some of your packages needs updates so this is a temporary fix while you update your packages or awaiting updates.

Solution 2

you open this file producing error GoogleApiHeadersPlugin.kt (cmd + click on it in console for macOS) and cut all the try catch part

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)
        }

so if method is empty and doing nothing

if (call.method == "getSigningCertSha1") {}else{}

then it works, I don't know why but it is a temporary solution, check if your libraries work ok

check this github issue

path to the file you should edit on windows os

C:\flutter\.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

Solution 3

you could downgrade your flutter version as you wait for the flutter libraries to be fixed

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1