该主题有很多答案,但大多数都与 Firebase 相关,即使我尝试使用或不使用 Firebase,我也会收到相同的一般错误
Exception com.google.android.gms.common.api.ApiException: 10: Developer console is not setup correctly.
。
问题:
使用任何构建(调试、发布),虽然我们有 CI-CD 通过 AppCenter 部署和分发应用程序,但在所有环境(测试、生产)中一切都很好,但是,一旦我们在 Google Play Console 中发布应用程序或使用 Play Console 中的 App Bundle Explorer 上传 AAB 并下载 APK 以在设备上进行本地测试,Google Sign-on 不起作用。
经过两周的研究并试图理解这意味着什么后,我做了以下事情。
我只有一个使用上传密钥 SHA1 的 Google Cloud Android OAuth 客户端 ID(我尝试使用 Google Play 签名 SHA1 添加第二个客户端 ID,但并没有真正改变任何内容)。这是尝试解决此答案中的问题https://stackoverflow.com/a/41034093/122769。 我实际上使用相同的 SHA1 进行调试和发布。请参阅下面的登录报告。另一个答案,但又与使用 Firebase 有关(https://stackoverflow.com/a/68094280/122769)。 我有一种感觉,我可能在需要为构建使用不同的 SHA1 方面做错了什么;但不确定如何处理它(不知道如何/在哪里添加 SHA1 进行发布https://stackoverflow.com/a/39347133/122769)
./gradlew signingReport
:
Variant: testRelease
Config: config
Store: some_path_to_store/release.jks
Alias: company
MD5: 57:MD5
SHA1: 99:SHA1
SHA-256: C3:SHA256
Valid until: Thursday, Month 9, 2045
Variant: prodRelease
Config: config
Store: some_path_to_store/release.jks
Alias: company
MD5: 57:MD5
SHA1: 99:SHA1
SHA-256: C3:SHA256
Valid until: Thursday, Month 9, 2045
代码:
package com.eight.app
import android.content.IntentSender
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import androidx.activity.result.ActivityResult
import androidx.activity.result.IntentSenderRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import com.google.android.gms.auth.api.identity.BeginSignInRequest
import com.google.android.gms.auth.api.identity.Identity
import com.google.android.gms.auth.api.identity.SignInClient
import com.google.android.gms.common.api.ApiException
class MainActivity : AppCompatActivity() {
private lateinit var errorText: TextView
private lateinit var googleButton: TextView
private lateinit var oneTapClient: SignInClient
private lateinit var signInRequest: BeginSignInRequest
private val activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult(), ::handleSignInResult)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.a_start)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
errorText = findViewById(R.id.errorText)
googleButton = findViewById(R.id.googleButton)
oneTapClient = Identity.getSignInClient(this)
signInRequest = BeginSignInRequest.builder()
.setPasswordRequestOptions(
BeginSignInRequest.PasswordRequestOptions.builder()
.setSupported(true)
.build(),
)
.setGoogleIdTokenRequestOptions(
BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
.setSupported(true)
// Your server's client ID, not your Android client ID.
.setServerClientId(getString(R.string.your_web_client_id))
// Only show accounts previously used to sign in.
.setFilterByAuthorizedAccounts(false)
.build(),
)
// Automatically sign in when exactly one credential is retrieved.
.setAutoSelectEnabled(true)
.build()
googleButton.setOnClickListener {
oneTapClient.beginSignIn(signInRequest)
.addOnSuccessListener(this) { result ->
try {
val intentSenderRequest = IntentSenderRequest.Builder(result.pendingIntent.intentSender).build()
activityResultLauncher.launch(intentSenderRequest)
} catch (e: IntentSender.SendIntentException) {
Log.e("oneTapSignIn", "Couldn't start One Tap UI: ${e.localizedMessage}")
errorText.text = "oneTapSignIn Couldn't start One Tap UI: ${e.localizedMessage}"
}
}
.addOnFailureListener(this) { e ->
// No Google Accounts found. Just continue presenting the signed-out UI.
Log.d("oneTapSignIn", e.localizedMessage)
errorText.text = "oneTapSignIn addOnFailureListener Couldn't start One Tap UI: ${e.localizedMessage}"
}
}
}
private fun handleSignInResult(result: ActivityResult) {
try {
val credential = oneTapClient.getSignInCredentialFromIntent(result.data)
val idToken = credential.googleIdToken
when {
idToken != null -> {
// Got an ID token from Google. Use it to authenticate
// with your backend.
errorText.text = "Token Success GOt token $idToken"
Log.d("onActivityResult", "Got ID token.")
}
else -> {
// Shouldn't happen.
Log.d("onActivityResult", "No ID token!")
errorText.text = "No ID token!"
}
}
} catch (e: ApiException) {
Log.d("onActivityResult", "ApiException No ID token!")
errorText.text = "Exception $e \n${e.localizedMessage} \n${e.message} \n ${e.cause} \n${e.stackTrace}!"
}
}
}
理想情况下,我想避免使用 Firebase,但无论如何,这仍然不起作用。有没有办法获得更多相关的调试信息?任何有关测试解决方案的想法将不胜感激:)