本文介绍了无法解析FirebaseOptions.Builder().setCredentials(...)中的setCredentials的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法解决FirebaseOptions.Builder().setCredentials()我已经在此链接中提及了答案,但是它并不能解决我的问题.这是我的代码:

Can not Resolved FirebaseOptions.Builder().setCredentials() i have referred to answers in this link but it did not solve my problem.here's my code:

FileInputStream serviceAccount =
                    new FileInputStream("./ServiceAccountKey.json");
            FirebaseOptions options = new FirebaseOptions.Builder()
                    .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                    .setDatabaseUrl("https://imiocr-f4522.firebaseio.com")
                    .build();

            FirebaseApp.initializeApp(options);

FirebaseApp.initializeApp(options);
            String customToken = FirebaseAuth.getInstance().createCustomTokenAsync("3mLImCwhyddkVZ9PWWNlw34pFVR2").get();

这是我的应用程序gradle文件的依赖项:

this is my app gradle file dependencies:

implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    implementation 'com.squareup.okhttp3:okhttp:3.11.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
    implementation 'com.wang.avi:library:2.1.3'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    implementation 'com.google.firebase:firebase-database:16.0.4'
    implementation 'com.firebase:firebase-client-android:2.5.2'
    implementation 'com.firebaseui:firebase-ui-database:4.2.0'
    implementation 'com.intuit.ssp:ssp-android:1.0.6'
    implementation 'com.google.firebase:firebase-storage:16.0.4'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'me.dm7.barcodescanner:zxing:1.9.8'
    implementation 'com.android.support:design:28.0.0-alpha1'

    //implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    implementation 'com.firebaseui:firebase-ui-storage:4.1.0'

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

setCredentials方法无法识别,请提供帮助.

setCredentials method is never recognized, please help.

推荐答案

您似乎正在尝试在同一应用中同时使用Admin SDK和用于Firebase的常规Android SDK.这不是受支持的方案.

You seem to be trying to use both the Admin SDK and the regular Android SDK for Firebase in the same app. This is not a supported scenario.

Admin SDK专用于在服务器和其他受信任的环境上使用.与您的用户共享的Android应用程序中的使用会导致Firebase项目遭受滥用.

The Admin SDK is specifically meant for use on servers, and other trusted environments. Using in Android apps that you share with your users opens your Firebase project up to abuse.

如果您需要应用程序中某些功能,这些功能在Android SDK中不可用,但可以通过Admin SDK来使用,请考虑将该功能包装在云函数,然后从您的Android应用.这样,您就可以控制可用的特定功能,而不必授予他们对Firebase项目的完全访问权限.

If you need some functionality in your app that is not available in the Android SDK, but is possible through the Admin SDK, consider wrapping that functionality in Cloud Functions, and calling that from your Android app. That way you can control what specific functionality you make available, instead of giving them full access to your Firebase project.

这篇关于无法解析FirebaseOptions.Builder().setCredentials(...)中的setCredentials的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 12:05