Skip to content

[google_sign_in] Failed to launch the selector UI. Hint: ensure the context parameter is an Activity-based context. #171122

Closed
flutter/packages
#9497

Description

@yocheco

What package does this bug report belong to?

google_sign_in

What target platforms are you seeing this bug on?

Android

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
google_sign_in:
    dependency: "direct main"
    description:
      name: google_sign_in
      sha256: dba1a1a79368d8ca464bf36ef94f528851efa9925e4a28bfc4aaefb1f5da2fc4
      url: "https://pub.dev"
    source: hosted
    version: "7.0.0"
  google_sign_in_android:
    dependency: transitive
    description:
      name: google_sign_in_android
      sha256: ac7cfb8216dc34d18221cc4ec9e0a07346a00420a37c548d151ac8ad49df0d7b
      url: "https://pub.dev"
    source: hosted
    version: "7.0.0"
  google_sign_in_ios:
    dependency: transitive
    description:
      name: google_sign_in_ios
      sha256: "59937a674827540d12253415626ec24cc7e633bb785e2d2ca4f1580323e55a0c"
      url: "https://pub.dev"
    source: hosted
    version: "6.0.0"
  google_sign_in_platform_interface:
    dependency: transitive
    description:
      name: google_sign_in_platform_interface
      sha256: "8736443134d2cccadd4f228d600177cb3947e36683466a6ab96877ce6932885a"
      url: "https://pub.dev"
    source: hosted
    version: "3.0.0"
  google_sign_in_web:
    dependency: transitive
    description:
      name: google_sign_in_web
      sha256: "09ac306b2787b48f19c857b9f93375b654f774643c75bd6a1a078c85f4f7b468"
      url: "https://pub.dev"
    source: hosted
    version: "1.0.0"

Steps to reproduce

1 install dependencie google_sign_in: ^7.0.0
2 create page

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';

class LogInView extends StatefulWidget {
  const LogInView({super.key});

  @override
  State<LogInView> createState() => _LogInViewState();
}

class _LogInViewState extends State<LogInView> {
  final List<String> scopes = <String>[];

  GoogleSignInAccount? _currentUser;

  Future<void> _handleAuthenticationEvent(GoogleSignInAuthenticationEvent event) async {
    // #docregion CheckAuthorization
    final GoogleSignInAccount? user = // ...
        // #enddocregion CheckAuthorization
        switch (event) {
          GoogleSignInAuthenticationEventSignIn() => event.user,
          GoogleSignInAuthenticationEventSignOut() => null,
        };

    setState(() {
      _currentUser = user;
    });

    // If the user has already granted access to the required scopes, call the
    // REST API.
  }

  Future<void> _handleAuthenticationError(Object e) async {
    print(e);
  }

  @override
  void initState() {
    super.initState();
    // #docregion Setup

    final GoogleSignIn signIn = GoogleSignIn.instance;
    unawaited(
      signIn
          .initialize(
            clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxx',
            serverClientId: 'xxxxxxxxxxxxxx',
          )
          .then((_) {
            signIn.authenticationEvents.listen(_handleAuthenticationEvent).onError(_handleAuthenticationError);
          }),
    );
    // #enddocregion Setup
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: InkWell(
          child: Text('Login'),
          onTap: () async {
            try {
              await GoogleSignIn.instance.authenticate();
            } catch (e) {
              // #enddocregion ExplicitSignIn
              print(e);

              // #docregion ExplicitSignIn
            }
          },
        ),
      ),
    );
  }
}

3 remplace
clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxx'
serverClientId: 'xxxxxxxxxxxxxx'

4 clic in Login

Expected results

start with the Google login process

Actual results

get error
code: 11417212
Failed to launch the selector UI. Hint: ensure the context parameter is an Activity-based context.

Code sample

Code sample
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';

class LogInView extends StatefulWidget {
  const LogInView({super.key});

  @override
  State<LogInView> createState() => _LogInViewState();
}

class _LogInViewState extends State<LogInView> {
  final List<String> scopes = <String>[];

  GoogleSignInAccount? _currentUser;

  Future<void> _handleAuthenticationEvent(GoogleSignInAuthenticationEvent event) async {
    // #docregion CheckAuthorization
    final GoogleSignInAccount? user = // ...
        // #enddocregion CheckAuthorization
        switch (event) {
          GoogleSignInAuthenticationEventSignIn() => event.user,
          GoogleSignInAuthenticationEventSignOut() => null,
        };

    setState(() {
      _currentUser = user;
    });

    // If the user has already granted access to the required scopes, call the
    // REST API.
  }

  Future<void> _handleAuthenticationError(Object e) async {
    print(e);
  }

  @override
  void initState() {
    super.initState();
    // #docregion Setup

    final GoogleSignIn signIn = GoogleSignIn.instance;
    unawaited(
      signIn
          .initialize(
            clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxx',
            serverClientId: 'xxxxxxxxxxxxxx',
          )
          .then((_) {
            signIn.authenticationEvents.listen(_handleAuthenticationEvent).onError(_handleAuthenticationError);
          }),
    );
    // #enddocregion Setup
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: InkWell(
          child: Text('Login'),
          onTap: () async {
            try {
              await GoogleSignIn.instance.authenticate();
            } catch (e) {
              // #enddocregion ExplicitSignIn
              print(e);

              // #docregion ExplicitSignIn
            }
          },
        ),
      ),
    );
  }
}

Screenshots or Videos

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
GoogleSignInException(code GoogleSignInExceptionCode.unknownError, Failed to launch the selector UI. Hint: ensure the `context` parameter is an Activity-based context., null)

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.32.4, on Ubuntu 24.04.2 LTS 6.11.0-26-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
    ! Unable to access driver information using 'eglinfo'.
      It is likely available from your distribution (e.g.: apt install mesa-utils)
[✓] Android Studio (version 2024.3)
[✓] VS Code (version unknown)
    ✗ Unable to determine VS Code version.
[✓] Connected device (3 available)
[✓] Network resources

Activity

  1. changed the title [-]Failed to launch the selector UI. Hint: ensure the `context` parameter is an Activity-based context.[/-] [+][google_sign_in] Failed to launch the selector UI. Hint: ensure the `context` parameter is an Activity-based context.[/+] on Jun 25, 2025
  2. pavkoccino commented on Jun 25, 2025

    @pavkoccino
  3. jhonessds commented on Jun 25, 2025

    @jhonessds
  4. yocheco commented on Jun 25, 2025

    @yocheco
    Author

    same issue, but this worked to me

    dependencies: google_sign_in: ^6.3.0

    dependency_overrides: google_sign_in_ios: ^5.9.0

    The issue is that version 6.x relies on Google’s deprecated login SDK. I’m currently updating from 6.x to 7.x, and while everything works fine on 6.x, I want to move forward since that SDK is no longer supported.

  5. added
    platform-androidAndroid applications specifically
    packageflutter/packages repository. See also p: labels.
    P1High-priority issues at the top of the work list
    fyi-androidFor the attention of Android platform team
    on Jun 25, 2025
  6. stuartmorgan-g commented on Jun 25, 2025

    @stuartmorgan-g
    Contributor

    It looks like this should be relatively straightforward to fix. It's not clear to my this didn't show up in my testing though, so once I have a PR I'll post instructions on testing it; it would be good to have validation that the fix is complete before landing it.

  7. yocheco commented on Jun 25, 2025

    @yocheco
    Author

    It looks like this should be relatively straightforward to fix. It's not clear to my this didn't show up in my testing though, so once I have a PR I'll post instructions on testing it; it would be good to have validation that the fix is complete before landing it.

    Thanks! If you share a PR or test instructions, I’ll be happy to try it out and confirm whether the issue is resolved on my side.

  8. stuartmorgan-g commented on Jun 25, 2025

    @stuartmorgan-g
    Contributor

    @yocheco (and anyone else interested in trying the fix), adding the following to your pubspec.yaml and running flutter pub get should pick up the change that I expect to fix this.

    dependency_overrides:
      google_sign_in_android:
        git:
          url: https://github.com/stuartmorgan-g/packages.git
          ref: google-sign-in-android-cm-activity-context
          path: packages/google_sign_in/google_sign_in_android
    

    Be sure not to leave this in your pubspec.yaml, as it will prevent getting any future fixes to the Android implementation of google_sign_in.

  9. 2 remaining items

  10. pongloongyeat commented on Jun 26, 2025

    @pongloongyeat
  11. Distantman commented on Jun 26, 2025

    @Distantman
  12. stuartmorgan-g commented on Jun 26, 2025

    @stuartmorgan-g
    Contributor

    flutter pub upgrade --unlock-transitive google_sign_in should pick up the fixed version of google_sign_in_android.

  13. jaybe78 commented on Jun 26, 2025

    @jaybe78

    flutter pub upgrade --unlock-transitive google_sign_in should pick up the fixed version of google_sign_in_android.

    Thanks @stuartmorgan-g This solves the problem

  14. pongloongyeat commented on Jun 28, 2025

    @pongloongyeat
  15. stuartmorgan-g commented on Jun 28, 2025

    @stuartmorgan-g
    Contributor

    The way to report an issue is to file a new issue, not to comment about it in a completely unrelated issue.

  16. github-actions commented on Jul 12, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  17. locked as resolved and limited conversation to collaborators on Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1High-priority issues at the top of the work listfyi-androidFor the attention of Android platform teamp: google_sign_inThe Google Sign-In pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions