我开发了一个 React Native 应用程序,并且使用 Expo Google-Sign-In 进行 Firebase 身份验证。当我尝试对 Android 上的独立 APK 进行身份验证时,我收到错误“DEVELOPER_ERROR”。
最初,我使用的是“Expo Google”,但那是 现已弃用,我的登录按钮在我的独立 APK 上没有执行任何操作。通过Expo Google方法,我发现我必须设置androidStandaloneAppClientId。即使在那之后,登录在身份验证后仍停留在 Google 主页。我尝试了使用自定义重定向 URI 的解决方案,如
重定向网址:
${AppAuth.OAuthRedirect}:/oauth2redirect/google
但这导致了另一个错误:redirect_uri 不匹配。
我改用了 Expo Google-Sign-In 库,每次我尝试进行身份验证时都会出现 DEVELOPER_ERROR。
之后,我尝试过:
我尝试了其他任何可能在 Google-Sign-In 博览会中涉及 DEVELOPER_ERROR 的现有线程中未提及的内容。
我在下面的代码中提到的变量来自以下内容:
SHA1 已生成并用于创建我的凭证,并且是我的 OAuth Android 客户端 ID 中使用的指纹。
我在文件中引用的客户端 ID 是我的 OAuth Web 客户端 ID。不过,我也尝试过使用 Android 版,但并没有改变任何东西。
api_key 中的“CurrentKey”是我的 Firebase 项目中的 API 密钥。
这是我的 Google 凭据页面的链接。
/* 我的 app.json: */
{
"expo": {
"name": "AssistiveNote",
"privacy": "public",
"description": "A note app for people who have trouble reading text.",
"slug": "assistivenote",
"sdkVersion": "33.0.0",
"version": "2.0.0",
"orientation": "portrait",
"icon": "./screens/images/icon.png",
"ios": {
"bundleIdentifier": "com.danyalbabar.assistivenote"
},
"android": {
"versionCode": 2,
"package": "com.danyalbabar.assistivenote",
"googleServicesFile": "./google-services.json",
"permissions": [ " " ],
"config": {
"googleSignIn": {
"certificateHash": "XXXX"
}
}
}
}
}
我的 google-services.json:
{
"project_info": {
"project_number": "XXXX",
"firebase_url": "https://era-gvision.firebaseio.com",
"project_id": "era-gvision",
"storage_bucket": "era-gvision.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "XXXX",
"android_client_info": {
"package_name": "com.danyalbabar.assistivenote"
}
},
"oauth_client": [
{
"client_id": "XXXX",
"client_type": 3
}
],
"api_key": [
{
"current_key": "XXXX"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "XXXX",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
eas
2022 年 11 月更新(安卓)如果您正在使用
eas
并获得 DEVELOPER_ERROR
:
eas credentials
(按照步骤获取 SHA1)google-services.json
(与上面相同的URL)并将其放入您的项目文件夹中app.json
以包含 expo.android.googleServicesFile: "./path/to/google-services.json"
app.json
中:仔细检查 expo.android.package
是否与 googleServicesFile 中的包匹配GoogleSignin.configure()
keytool -printcert -jarfile app.apk
(将打印 SHA1)这是配置不匹配。确保您的 android/app/google-services.json 正确。
您可能需要将 SHA 证书指纹添加到 Firebase 配置中。按照本文中的说明查找您的 SHA1 指纹:密钥库证书的 SHA-1 指纹。然后,转到 https://console.firebase.google.com/,选择您的应用程序,然后在项目设置(左上角的齿轮图标)-> 您的应用程序 -> SHA 证书指纹下添加 SHA1 值
如果您将配置对象中的 webClientId 传递给 GoogleSignin.configure(),请确保其正确。您可以从 Google Developer Console 获取您的 webClientId。它们列在“OAuth 2.0 客户端 ID”下。
如果您在调试模式下运行应用程序并且不使用 webClientId 或者您确定它是正确的,则问题可能是签名(SHA-1 或 SHA-256)不匹配。您需要将以下内容添加到 android/app/build.gradle 中:
signingConfigs {
debug {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
release {
...
}
就我而言,我必须将 androidClientId 和 webClientId 传递给配置方法,
GoogleSignin.configure({
webClientId: '',
androidClientId:'',
});
为了获取凭据,请在此页面上选择您的项目https://console.cloud.google.com/apis/credentials
由于我在 Google Console 中没有 webClientId 配置文件,并且我只希望 Android 删除 webClientId 在示例中对我有用,因此 webClientId 是提供的唯一属性。还需要添加 client_type: 3。
export default {
//webClientId: '732421745157-983dllmj1ea30oqi0j7g0ohd6veei1tm.apps.googleusercontent.com',
androidClientId: '732421745157-983dllmj1ea30oqi0j7g0ohd6veei1tm.apps.googleusercontent.com',
client_type: 3 };
总的来说,这个 API 似乎有很多损坏的行为,现在已被弃用。当时我开始使用电子邮件/密码身份验证,但现在有更新的 Expo API 以新的方式实现。