Flutter:Google 和 Firebase 登录在生产环境中不起作用
Flutter: Google and Firebase login not working in production
我使用 google_sign_in 和 firebase_auth。这在模拟器中运行良好,在编译 apk 并直接在真实设备上尝试时也能正常工作,但是当我将其发布到 Google Play 并从中安装我的应用程序时,它就是行不通。
我没有收到任何错误。登录出现,当我点击我的一个帐户时,它没有做任何事情就关闭了。
从 Google 获取凭据后,我使用 Firebase 登录以获取该用户的真实数据:
Future googleSignIn(BuildContext context,
[String? email, facebookCredential]) async {
try {
GoogleSignInAccount googleUser;
dynamic popup = await _googleSignIn.signIn();
// cancelled login
if (popup == null) {
return null;
}
googleUser = popup;
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
await _firebaseCredential(context, credential);
} catch (error) {
return null;
}
}
_firebaseCredential(BuildContext context, credential) async {
User user =
(await FirebaseAuth.instance.signInWithCredential(credential)).user!;
await firebaseProfile.updateUserData(user);
// from here I do some Firebase changes but Google, Facebook, Apple and email login
}
所有设置(包括 AndroidManifest.xml
中所需的权限)都可以
这可能是因为您没有在 android 上添加互联网权限。在调试模式下它会自动启用但在发布模式下不会。
您必须在 AndroidManifest.xml
中添加以下行:
<manifest xmlns:android...>
...
<uses-permission android:name="android.permission.INTERNET" />
<application ...
</manifest>
据我了解,我认为这是因为 Play 商店构建缺少需要包含在 Firebase 控制台中的 SHA 指纹。
在开发过程中,我们可能会在 Firebase 控制台中添加 SHA-1 and SHA-256 fingerprints 或 debug.keystore。
And we need to keep in mind that, during the release build you also
want to add the fingerprints of release keystore to the Firebase
Console (same like of debug).
我不知道您在推送到 Play 商店之前是否在真实设备中尝试过发布版本。但这可能是原因。
另请注意,如果您选择 Google Play Signing process, you should also include the SHA fingerprints of Google Certificate/Keystore from Google developer console of your application. This link 将帮助您从 Play 商店控制台获取指纹。
注意:确保您已经更新了项目中包含的 google-services.json
希望这对您有所帮助,或者如果您遇到其他问题,请告诉我。
我使用 google_sign_in 和 firebase_auth。这在模拟器中运行良好,在编译 apk 并直接在真实设备上尝试时也能正常工作,但是当我将其发布到 Google Play 并从中安装我的应用程序时,它就是行不通。
我没有收到任何错误。登录出现,当我点击我的一个帐户时,它没有做任何事情就关闭了。
从 Google 获取凭据后,我使用 Firebase 登录以获取该用户的真实数据:
Future googleSignIn(BuildContext context,
[String? email, facebookCredential]) async {
try {
GoogleSignInAccount googleUser;
dynamic popup = await _googleSignIn.signIn();
// cancelled login
if (popup == null) {
return null;
}
googleUser = popup;
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
await _firebaseCredential(context, credential);
} catch (error) {
return null;
}
}
_firebaseCredential(BuildContext context, credential) async {
User user =
(await FirebaseAuth.instance.signInWithCredential(credential)).user!;
await firebaseProfile.updateUserData(user);
// from here I do some Firebase changes but Google, Facebook, Apple and email login
}
所有设置(包括 AndroidManifest.xml
中所需的权限)都可以
这可能是因为您没有在 android 上添加互联网权限。在调试模式下它会自动启用但在发布模式下不会。
您必须在 AndroidManifest.xml
中添加以下行:
<manifest xmlns:android...>
...
<uses-permission android:name="android.permission.INTERNET" />
<application ...
</manifest>
据我了解,我认为这是因为 Play 商店构建缺少需要包含在 Firebase 控制台中的 SHA 指纹。
在开发过程中,我们可能会在 Firebase 控制台中添加 SHA-1 and SHA-256 fingerprints 或 debug.keystore。
And we need to keep in mind that, during the release build you also want to add the fingerprints of release keystore to the Firebase Console (same like of debug).
我不知道您在推送到 Play 商店之前是否在真实设备中尝试过发布版本。但这可能是原因。
另请注意,如果您选择 Google Play Signing process, you should also include the SHA fingerprints of Google Certificate/Keystore from Google developer console of your application. This link 将帮助您从 Play 商店控制台获取指纹。
注意:确保您已经更新了项目中包含的 google-services.json
希望这对您有所帮助,或者如果您遇到其他问题,请告诉我。