简体   繁体   English

无法在 flutter 上使用 firebase 进行谷歌登录; “期待活页夹,但结果为空!”

[英]Cannot proceed google login with firebase on flutter; "Expecting binder but got null!"

I am new to mobile app and using flutter to implement google social login with firebase auth.我是移动应用程序的新手,使用 flutter 通过 firebase 身份验证实现谷歌社交登录。 I checked official resources and implemented a login logic like below;我检查了官方资源并实现了如下登录逻辑;

main.dart主要.dart

import 'package:atlas_app/auth/signup.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  FirebaseAuth.instance.useAuthEmulator('10.0.2.2', 9099);

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const SignUp());
  }
}

signin.dart登录.dart

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_signin_button/button_list.dart';
import 'package:flutter_signin_button/button_view.dart';
import 'package:google_sign_in/google_sign_in.dart';

class SignUp extends StatefulWidget {
  const SignUp({Key? key}) : super(key: key);

  @override
  State<SignUp> createState() => _SignUpState();
}

class _SignUpState extends State<SignUp> {
  FirebaseAuth auth = FirebaseAuth.instance;

Future<UserCredential> signInWithGoogle() async {
  // Trigger the authentication flow
  final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();

  // Obtain the auth details from the request
  final GoogleSignInAuthentication? googleAuth = await googleUser?.authentication;

  // Create a new credential
  final credential = GoogleAuthProvider.credential(
    accessToken: googleAuth?.accessToken,
    idToken: googleAuth?.idToken,
  );

  // Once signed in, return the UserCredential
  return await FirebaseAuth.instance.signInWithCredential(credential);
}

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.blue,
          elevation: 8,
          title: const Text("Sign Up"),
        ),
        body: Container(
          padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 50),
          child: Form(
              child: Column(
            children: [
              SignInButton(
                Buttons.Google,
                onPressed: () async => {signInWithGoogle()},
              )
            ],
          )),
        ));
  }
}

It is so simple that I expected to work, but when I tapped the sign-in button on android emulator(Pixel4 with android API 33, arm64) my app is crashed and debug console says;它非常简单,我希望可以工作,但是当我点击 android 模拟器(Pixel4 with android API 33,arm64)上的登录按钮时,我的应用程序崩溃了,调试控制台说;

W/Parcel  (13587): Expecting binder but got null!
D/EGL_emulation(13587): app_time_stats: avg=697.35ms min=151.31ms max=1243.39ms count=2
E/JavaBinder(13587): !!! FAILED BINDER TRANSACTION !!!  (parcel size = 324)
W/GmsClient(13587): IGmsServiceBroker.getService failed
W/GmsClient(13587): android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died, but this could also be caused by running out of binder buffe
W/GmsClient(13587):     at android.os.BinderProxy.transactNative(Native Method)
W/GmsClient(13587):     at android.os.BinderProxy.transact(BinderProxy.java:584)
W/GmsClient(13587):     at com.google.android.gms.common.internal.zzac.getService(com.google.android.gms:play-services-basement@@18.0.0:8)
W/GmsClient(13587):     at com.google.android.gms.common.internal.BaseGmsClient.getRemoteService(com.google.android.gms:play-services-basement@@18.0.0:14)
W/GmsClient(13587):     at com.google.android.gms.common.api.internal.zabt.run(com.google.android.gms:play-services-base@@18.0.1:7)
W/GmsClient(13587):     at android.os.Handler.handleCallback(Handler.java:942)
W/GmsClient(13587):     at android.os.Handler.dispatchMessage(Handler.java:99)
W/GmsClient(13587):     at android.os.Looper.loopOnce(Looper.java:201)
W/GmsClient(13587):     at android.os.Looper.loop(Looper.java:288)
W/GmsClient(13587):     at android.os.HandlerThread.run(HandlerThread.java:67)
W/Parcel  (13587): Expecting binder but got null!
D/EGL_emulation(13587): eglCreateContext: 0xb400006ff0487dd0: maj 3 min 0 rcv 3
D/EGL_emulation(13587): eglCreateContext: 0xb400006ff0489e10: maj 3 min 0 rcv 3
D/HostConnection(13587): createUnique: call
D/HostConnection(13587): HostConnection::get() New Host Connection established 0xb400006ff0488f10, tid 13652
D/HostConnection(13587): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
D/EGL_emulation(13587): eglMakeCurrent: 0xb400006ff0489e10: ver 3 0 (tinfo 0x720c8be280) (first time)
D/HostConnection(13587): createUnique: call
D/HostConnection(13587): HostConnection::get() New Host Connection established 0xb400006ff0488010, tid 13651
D/HostConnection(13587): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
D/EGL_emulation(13587): eglMakeCurrent: 0xb400006ff0487dd0: ver 3 0 (tinfo 0x720c8be300) (first time)
D/EGL_emulation(13587): eglCreateContext: 0xb400006ff0486f90: maj 3 min 0 rcv 3
E/JavaBinder(13587): !!! FAILED BINDER TRANSACTION !!!  (parcel size = 324)
W/GmsClient(13587): IGmsServiceBroker.getService failed
W/GmsClient(13587): android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died, but this could also be caused by running out of binder buffe
......

I have been tackling this issue, but no clue to fix yet.我一直在解决这个问题,但还没有解决的线索。 Any help would be very appreciated!任何帮助将不胜感激!

in main.dart add this在 main.dart 添加这个

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(const Foo());
}

我发现在模拟器上运行时,即使是官方文档中的示例也失败了。

I found the solution here.我在这里找到了解决方案。 the error come from the emulator, Change the emulator version from 31.3.10 to 30.2.9 https://youtu.be/qo3SbdbXFos错误来自模拟器,将模拟器版本从 31.3.10 更改为 30.2.9 https://youtu.be/qo3SbdbXFos

Since I can't comment on the question, I'll "answer" it with a little help.由于我无法对这个问题发表评论,因此我会在一些帮助下“回答”它。

As stated here , the problem only occurs when the device does not have the PlayStore installed.如此处所述,仅当设备未安装 PlayStore 时才会出现问题。

I'm also seeing this error, but it seems that no one knows the solution.我也看到了这个错误,但似乎没有人知道解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM