问题
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();
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 method is never recognized, please help.
回答1:
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.
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.
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.
来源:https://stackoverflow.com/questions/53207292/cannot-resolve-setcredentials-in-firebaseoptions-builder-setcredentials