无法解析FirebaseOptions.Builder()。setCredentials()

时间:2018-07-05 07:42:30

标签: java android firebase firebase-authentication

尝试使用customToken实现Firebase身份验证。

在执行以下操作时出错:

FirebaseOptions options = new FirebaseOptions.Builder()
                         .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                .setDatabaseUrl("path to file") //different in actual
                .build();

        FirebaseApp.initializeApp(options); 

它说无法解析setCredentials(),在此之后,当我尝试创建令牌时,给出了相同的错误:

FirebaseAuth.getInstance().createCustomToken(uid);

在网上搜索找不到解决方案,请帮助

使用的依赖项如下:

implementation 'com.google.firebase:firebase-core:11.0.4'
implementation 'com.google.firebase:firebase-messaging:11.0.4'
implementation 'com.google.firebase:firebase-appindexing:11.0.4'
implementation 'com.google.firebase:firebase-database:11.0.4'
implementation 'com.google.firebase:firebase-storage:11.0.4'
implementation 'com.google.firebase:firebase-auth:11.0.4'
implementation 'com.google.firebase:firebase-perf:16.0.0'
implementation 'com.firebase:firebase-client-android:2.5.2+'
implementation 'com.firebase:firebase-client-android:2.5.2+'
implementation 'com.google.android.gms:play-services-analytics:11.0.4'
implementation 'com.google.android.gms:play-services-location:11.0.4'
implementation 'com.google.android.gms:play-services-auth:11.0.4'

2 个答案:

答案 0 :(得分:1)

问题的完美答案是将以下依赖项添加到您的应用程序级别文件中。

implementation 'com.google.firebase:firebase-admin:6.2.0'

所有问题都将得到解决。

答案 1 :(得分:0)

要解决此问题,请使用以下方式更改您的依存关系:

implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-appindexing:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-perf:16.0.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'

另外,请不要忘记添加:

classpath 'com.google.gms:google-services:4.0.1'

在您的build.gradle文件(项目)中。

请参阅here更多信息。

请同时删除:

implementation 'com.firebase:firebase-client-android:2.5.2+'

因为不再需要,compile "com.google.firebase:firebase-database:16.0.1"将按照here的描述进行操作。