When setting up Google Authentication using Kotlin, the following error arises: "Type inference failed. Expected type mismatch: inferred type is GoogleSignInAccount? But GoogleSignInAccount was expected". The error is coming from line "val account: GoogleSignInAccount = completedTask.getResult(ApiException::class.java)" This code is coming almost in its entirety from https://developers.google.com/identity/sign-in/android/sign-in
I have checked a question posted on here with the exact same problem but answers to that one couldn't solve my problem (nor her's Type mismatch: inferred type is GoogleSignInAccount? but GoogleSignInAccount was expected > Task :app:buildInfoGeneratorFdroidDebug).
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SIGN_IN) {
val task: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(data)
handleResult (task)
}else {
Toast.makeText(this, "Problem in execution order :(", Toast.LENGTH_LONG).show()
}
}
private fun handleResult (completedTask: Task<GoogleSignInAccount>) {
try {
val account: GoogleSignInAccount = completedTask.getResult(ApiException::class.java) #error in this line
updateUI (account)
} catch (e: ApiException) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
}
}
If anyone has suggestions on what the cause of this error could be, that would be great.
val account: GoogleSignInAccounttoval account: GoogleSignInAccount?- Hayi Nukman