«Не удалось получить токен аутентификации FIS» для новых устройств

# #flutter #firebase-authentication

Вопрос:

Я знаю, что есть еще несколько сообщений с той же ошибкой, но ни одно из решений еще не сработало для меня. Эта проблема возникает только на устройствах, которые еще не выполнили успешный вход в систему с помощью Firebase ранее. Например, если я очищу кэш и удалю его на своем личном устройстве (pixel 5), я смогу переустановить его из Android Studio, и все это будет работать нормально. Но попытка позвонить по телефону друзей в первый раз завершается неудачей со следующим:

Полный вывод ошибок:

 I/FLTFireMsgService( 4990): FlutterFirebaseMessagingBackgroundService started!
E/FirebaseMessaging( 4990): Failed to get FIS auth token
E/FirebaseMessaging( 4990): java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.
E/FirebaseMessaging( 4990):     at com.google.android.gms.tasks.Tasks.zza(com.google.android.gms:play-services-tasks@@17.2.1:5)
E/FirebaseMessaging( 4990):     at com.google.android.gms.tasks.Tasks.await(com.google.android.gms:play-services-tasks@@17.2.1:8)
E/FirebaseMessaging( 4990):     at com.google.firebase.messaging.GmsRpc.setDefaultAttributesToBundle(com.google.firebase:firebase-messaging@@22.0.0:11)
E/FirebaseMessaging( 4990):     at com.google.firebase.messaging.GmsRpc.startRpc(com.google.firebase:firebase-messaging@@22.0.0:1)
E/FirebaseMessaging( 4990):     at com.google.firebase.messaging.GmsRpc.getToken(com.google.firebase:firebase-messaging@@22.0.0:2)
E/FirebaseMessaging( 4990):     at com.google.firebase.messaging.FirebaseMessaging.lambda$blockingGetToken$8$FirebaseMessaging(com.google.firebase:firebase-messaging@@22.0.0:1)
E/FirebaseMessaging( 4990):     at com.google.firebase.messaging.FirebaseMessaging$Lambda$9.start(Unknown Source:4)
E/FirebaseMessaging( 4990):     at com.google.firebase.messaging.RequestDeduplicator.getOrStartGetTokenRequest(com.google.firebase:firebase-messaging@@22.0.0:6)
E/FirebaseMessaging( 4990):     at com.google.firebase.messaging.FirebaseMessaging.lambda$blockingGetToken$9$FirebaseMessaging(com.google.firebase:firebase-messaging@@22.0.0:1)
E/FirebaseMessaging( 4990):     at com.google.firebase.messaging.FirebaseMessaging$Lambda$8.then(Unknown Source:4)
E/FirebaseMessaging( 4990):     at com.google.android.gms.tasks.zze.run(com.google.android.gms:play-services-tasks@@17.2.1:1)
E/FirebaseMessaging( 4990):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/FirebaseMessaging( 4990):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/FirebaseMessaging( 4990):     at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.6.0:2)
E/FirebaseMessaging( 4990):     at java.lang.Thread.run(Thread.java:923)
E/FirebaseMessaging( 4990): Caused by: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.
E/FirebaseMessaging( 4990):     at com.google.firebase.installations.remote.FirebaseInstallationServiceClient.createFirebaseInstallation(FirebaseInstallationServiceClient.java:213)
E/FirebaseMessaging( 4990):     at com.google.firebase.installations.FirebaseInstallations.registerFidWithServer(FirebaseInstallations.java:533)
E/FirebaseMessaging( 4990):     at com.google.firebase.installations.FirebaseInstallations.doNetworkCallIfNecessary(FirebaseInstallations.java:388)
E/FirebaseMessaging( 4990):     at com.google.firebase.installations.FirebaseInstallations.lambda$doRegistrationOrRefresh$2$FirebaseInstallations(FirebaseInstallations.java:377)
E/FirebaseMessaging( 4990):     at com.google.firebase.installations.-$Lambda$FirebaseInstallations$SC1awUtshakVcZWKWh8TCfIkd4g.run(Unknown Source:4)
E/FirebaseMessaging( 4990):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/FirebaseMessaging( 4990):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/FirebaseMessaging( 4990):     ... 1 more
E/FirebaseMessaging( 4990): Topic sync or token retrieval failed on hard failure exceptions: java.util.concurrent.ExecutionException: java.io.IOException: AUTHENTICATION_FAILED. Won't retry the operation.
E/flutter ( 4990): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: [firebase_messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: AUTHENTICATION_FAILED
E/flutter ( 4990): #0      MethodChannelFirebaseMessaging.getToken (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:228:7)
E/flutter ( 4990): <asynchronous suspension>
E/flutter ( 4990): #1      PushNotificationsManager.init (package:myapp/services/push_notification_manager.dart:68:13)
E/flutter ( 4990): <asynchronous suspension>
E/flutter ( 4990): #2      StartupViewModel.preSignInSetup (package:myapp/ui/views/startup/startup_viewmodel.dart:72:5)
E/flutter ( 4990): <asynchronous suspension>
E/flutter ( 4990): #3      StartupViewModel.initApp (package:myapp/ui/views/startup/startup_viewmodel.dart:35:5)
E/flutter ( 4990): <asynchronous suspension>
E/flutter ( 4990): 
 

pubspec.yaml:

 name: myapp
description: A new Flutter application.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a  .
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0 8

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  animations: ^1.1.1
  ansicolor: ^1.0.0
  app_tracking_transparency: ^2.0.1
  auto_route: ^0.6.9
  badges: ^2.0.1
  carousel_slider: ^4.0.0-nullsafety.0
  cached_network_image: ^3.0.0-nullsafety
  country_code_picker: ^2.0.2
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  flutter_animated_dialog: ^1.2.0
  # the package from pub.dev is not upgraded to null-safety, so using a fork which is
  flutter_emoji_keyboard:
    git:
      url: https://github.com/bobs4462/emoji_keyboard.git
      ref: master
  firebase_auth: ^3.0.1
  firebase_core: ^1.4.0
  firebase_dynamic_links: ^2.0.7
  firebase_messaging: ^10.0.4
  firebase_storage: ^8.0.0
#  flutter_dotenv: ^5.0.0
  flutter_dotenv:
    git: git@github.com:e-e/flutter_dotenv.git
  flutter_hooks: ^0.16.0
  flutter_icons: ^1.1.0
  flutter_map: ^0.13.0
  flutter_spinkit: ^5.0.0
  flutter_typeahead: ^3.1.2
  geolocator: ^7.0.1
  get_it: ^7.1.3
  google_fonts: ^2.1.0
  http: ^0.13.0
  image_picker: ^0.7.2
  intl: ^0.17.0
  logger: ^1.0.0
  multi_image_picker: ^4.8.0
  observable_ish: ^3.0.0
  package_info: ^2.0.2
  pin_code_fields: ^7.0.0-nullsafety
  reorderables: ^0.3.2
  sentry_flutter: ^5.1.0
  sliding_up_panel: ^1.0.2
  stacked: ^2.2.3
  stacked_hooks: ^0.1.3 2
  stacked_services: ^0.8.13
  uuid: ^3.0.1
  web_socket_channel: ^1.0.9
  wechat_assets_picker: ^5.5.6
  wechat_camera_picker: ^2.2.0
  community_material_icon: ^5.9.55

dev_dependencies:
  auto_route_generator: ^0.6.10
  build_runner: ^1.10.6
  flutter_launcher_icons: ^0.9.2
  flutter_test:
    sdk: flutter
#  integration_test:
#    sdk: flutter
#  flutter_driver:
#    sdk: flutter

#dependency_overrides:
#  archive: ">=3.1.2"

flutter_icons:
  android: true
  image_path_android: "images/app_logo_android.png"
  adaptive_icon_background: "images/ic_launcher_adaptive_back.png"
  adaptive_icon_foreground: "images/ic_launcher_adaptive_fore.png"
  ios: true
  remove_alpha_ios: true
  image_path_ios: "images/launcher-icon.png"

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - images/
    - assets/
    - .env
    - .env-development
    - .env-production

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages
 

android/build.gradle :

 buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.8'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
 

android/app/build.gradle

 def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs  = 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "io.twibs.twibs"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }

}

flutter {
    source '../..'
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:28.3.0')
    implementation 'com.google.firebase:firebase-analytics'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-auth:19.3.2'
    implementation "com.google.firebase:firebase-messaging:20.2.4"
    implementation 'com.android.support:multidex:1.0.3'
}
 

This is what is being called where the stack trace points to:

 _firebaseMessaging = FirebaseMessaging.instance;

settings = await _firebaseMessaging.requestPermission(
  alert: true,
  announcement: true,
  badge: true,
  sound: true,
);
token = await _firebaseMessaging.getToken(); // <-- error here
 

I think this is the first place where a firebase service is doing anything on app load, so I’m not sure if it is specific to Firebase Messaging. But I honestly have no idea.

I’ve followed the FlutterFire instructions, app verification setup, as well as putting the google-services.json in android/google-services.json and android/app/google-services.json .

I’ve also tried providing FirebaseOptions , which didn’t seem to change anything.

I really have no idea what to do at this point. This is pretty much the only thing left before I can release the app and none of the solutions I’ve seen have worked. Thank you for any help in advance.