Firebase gives you the ability to add the Firebase Admin SDK to your server:
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
Previously, I used the following code, however, I am now getting a message in Eclipse that "The constructor FirebaseOptions.Builder() is deprecated".
InputStream serviceAccount = context.getResourceAsStream("/WEB-INF/[my-web-token].json");
try {
options = new FirebaseOptions.Builder() // <--DEPRECATED
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
//.setDatabaseUrl(FIREBASE_DATABASE_URL)
.build();
} catch(Exception e) {
e.printStackTrace();
}
firebaseApp = FirebaseApp.initializeApp(options);
Sure enough, Firebase advises:
Builder() This constructor is deprecated. Use builder() instead.
The constructor now looks like this:
public static FirebaseOptions.Builder builder ()
How is this accomplished? if I just replace
FirebaseOptions options = FirebaseOptions.Builder()
...
with the new builder...
FirebaseOptions options = FirebaseOptions.builder()
...
I get an error:
FirebaseOptions.builder cannot be resolved to a type
and the file will not compile.
Can someone show me how to use the new constructor or point me to the updated Firebase documentation? I can't find it.