【问题标题】:Firebase InstanceId: binding to the service failed: KotlinFirebase InstanceId:绑定到服务失败:Kotlin
【发布时间】:2020-04-23 14:00:18
【问题描述】:

应用程序成功启动,但在调试时收到此错误消息。 FirebaseInstanceId:绑定到服务失败

应用构建 Gradle:

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId ""
    minSdkVersion 16
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true // enable mun

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

Android 清单:

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="GoogleAppIndexingWarning">
    <activity android:name=".FilterPage"></activity>
    <activity android:name=".filterdashboard" />
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

【问题讨论】:

    标签: android firebase kotlin


    【解决方案1】:

    我已经添加了

    <uses-permission android:name="android.permission.INTERNET"/>
    

    在我的清单文件中并删除了 Firebase InstanceId:绑定到服务失败。希望它会有所帮助。

    【讨论】:

    • 这个很奇怪。 “绑定到服务失败”并没有更早发生,并且在几天后突然出现,即使我在没有此权限的情况下测试了相同的功能。对这种行为有什么想法?
    【解决方案2】:

    我下载了最新版本的google-service.json(可以通过 Firebase 设置完成)。就我而言,oauth_client 添加了一个新条目。与文件系统同步并重建我的应用后,警告似乎不再出现。

    编辑 20-02-2020:在对此进行了更多测试之后,不幸的是,它最终似乎没有帮助。在我的情况下,只有在卸载应用程序后第一次启动应用程序时才会出现错误消息 - 在大多数其他情况下,它不会发生。

    【讨论】:

      【解决方案3】:

      请尝试使用实际设备。根据我的观察,即使您已经下载了与 Google 服务相关的所有必需库,在使用模拟器时也会出现这种错误。我还能够从 FirebaseInstanceId 中看到其他错误。

      【讨论】:

        【解决方案4】:

        在我的情况下,在模拟器 (API: R) 上登录 Google Play 可以解决问题。我认为这与 Play Services 有关。

        【讨论】:

          【解决方案5】:

          在应用标签内添加服务标签

          <application>
          
          ....
          
             <activity
          
                   ....
          
             </activity>
          
             <service
                 android:name=".MyFirebaseMessagingService"
                 android:exported="false">
                 <intent-filter>
                     <action android:name="com.google.firebase.MESSAGING_EVENT" />
                 </intent-filter>
              </service>
          
          </application>
          

          然后添加一个新的 kotlin 文件 - MyFirebaseMessagingService.kt

          import com.google.firebase.messaging.FirebaseMessagingService;
          
          public class MyFirebaseMessagingService extends FirebaseMessagingService {
          
              @Override
              public void onNewToken(String s) {
                  super.onNewToken(s);
                  System.out.println("NEW_TOKEN :::::::::::::::::::::::::: "+s);
              }
          
          }
          

          手动卸载应用程序并重新安装。这会起作用。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-11-06
            • 2021-02-22
            • 1970-01-01
            • 2020-08-01
            • 1970-01-01
            • 2013-11-24
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多