Can not resolve FirebaseOptions using latest Firebase SDK dependency

社会主义新天地 提交于 2019-12-06 07:12:32

Fortunately Firebase has updated their documentation and now suggesting these below maven configuraiton , which resolved the problem perfectly. I think it was a outdated documentation issue.

<dependency>
  <groupId>com.google.firebase</groupId>
  <artifactId>firebase-admin</artifactId>
  <version>5.5.0</version>
</dependency>

Please follow this link Firebase SDK Installation guide

In addition , if you are behind corporate proxy, you need to set proxy like this:

System.setProperty("https.proxyHost", "your_proxy_host");
System.setProperty("https.proxyPort", "your_proxy_port");

so complete code to initialize Firebase instance is:

 URL fileUrl = FirebaseConfig.class.getClassLoader().getResource(configPath);
FileInputStream fisTargetFile = new FileInputStream(fileUrl.getFile());
System.setProperty("https.proxyHost", "your_proxy_host");
System.setProperty("https.proxyPort", "your_proxy_port");
    FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredentials(GoogleCredentials.fromStream(fisTargetFile))
            .setDatabaseUrl(databaseUrl)
            .build();
    FirebaseApp.initializeApp(options);

Hope it will be helpful to others.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!