【问题标题】:Invalid sender Id while getting device token获取设备令牌时发件人 ID 无效
【发布时间】:2019-07-15 20:27:09
【问题描述】:

我正在我的 Android 应用中进行 Firebase 云消息传递设置。我不是第一次做,我做了很多次。但是这次我在尝试获取设备令牌时遇到了一个奇怪的错误“无效的发件人 ID”。我从来没有在我的项目中使用过任何发件人 ID,除了项目编号默认存在于 google-services.json 文件中。请帮助我摆脱了这个

.我正在使用此方法生成令牌。我在我的项目中添加了 google-services.json 文件

 FirebaseInstanceId.getInstance().getInstanceId()
            .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
                @Override
                public void onComplete(@NonNull Task<InstanceIdResult> task) {
                    if (!task.isSuccessful()) {
                        Toast.makeText(WelcomeActivity.this,task.getException().getMessage(),Toast.LENGTH_LONG).show();
                        Log.w("getInstanceId failed", task.getException());
                        return;
                    }

                    // Get new Instance ID token
                    String token = task.getResult().getToken();
                    Log.v("sssskkkk",token);

                }
            });

我在我的项目中使用以下依赖项

 implementation 'com.android.support.constraint:constraint-layout:1.0.2'
api fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.firebase:firebase-messaging:17.3.4'
testImplementation('com.android.support.test.espresso:espresso-core:2.2.2')

implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'me.relex:circleindicator:1.2.2@aar'
implementation 'org.immutables:gson:2.4.0'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'

implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
implementation 'com.borjabravo:readmoretextview:2.0.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.github.mabbas007:TagsEditText:1.0.5'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'


implementation 'com.android.support:support-core-utils:28.0.0'

implementation 'com.karumi:dexter:4.2.0'

我很确定在 Firebase 云消息传递的实现中我没有遗漏任何东西。此外,当我在具有相同包名称的不同项目中使用相同的 google-services.json 时,一切正常。

【问题讨论】:

    标签: java android firebase-cloud-messaging


    【解决方案1】:

    是的,我在花了大约 30 个小时后终于解决了它。该代码是由以前的开发人员完成的,我发现有两个 google-services.json 文件,一个在 app 文件夹中,另一个在调试文件夹中,所以发件人 ID 是不匹配。所以我想建议所有遇到此错误的人:-

    1. 应检查您是否已将文件复制到正确的应用文件夹中。
    2. 应检查文件是否正确并与 FCM 中最新下载的 google-services.json 文件匹配
    3. 是否应该检查您的项目中是否存在任何重复的 google-services.json 文件?

    【讨论】:

      【解决方案2】:

      我也有同样的例外。 (java.io.IOException: INVALID_SENDER)

      我已成功获得注册令牌,但在删除 firebase 项目并重新创建 firebase 项目后,我开始收到 Invalid sender 异常。

      我确认我复制了正确的 google-services.json 文件,但发生了异常。

      解决方案很简单。 只需删除下面生成的 google-services 文件夹即可。

      Project_Name\app\build\generated\res\google-services
      

      如果您删除该文件夹并重新构建项目,则正确的 google-services 文件夹是由当前的 google-services.json 文件创建的。 现在您可以获得 Firebase 注册令牌。

      【讨论】:

      • 也可以通过gradlew clean命令完成
      猜你喜欢
      • 1970-01-01
      • 2021-11-23
      • 2021-11-27
      • 2014-05-07
      • 2020-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多