Java Maven项目-Firebase连接错误:java.lang.NoSuchMethodError

时间:2019-02-02 17:30:51

标签: java maven firebase firebase-realtime-database firebase-authentication

  

java.lang.NoSuchMethodError:com.google.common.collect.Iterables.getFirst(Ljava / lang / Iterable; Ljava / lang / Object;)Ljava / lang / Object;       在com.google.auth.oauth2.OAuth2Credentials.getFromServiceLoader(OAuth2Credentials.java:334)       ...

Java测试用例:

public void connectToFirebase() throws IOException {

    System.out.println("connectToFirebase()");
    FileInputStream serviceAccount;
    serviceAccount = new FileInputStream
            ("C:\\...\\social-networking-site-ae94d-firebase-adminsdk-xxxxx-xxxxxxxxxx.json");
    Map<String, Object> auth = new HashMap<String, Object>();
    auth.put("uid", "my-service-worker");
    System.out.println("-1-"); // error occurred after this line
    FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredentials(GoogleCredentials.fromStream(serviceAccount))
            .setDatabaseUrl("https://social-networking-site-ae94d.firebaseio.com")
            .setDatabaseAuthVariableOverride(auth)
            .build();
    FirebaseApp.initializeApp(options);
    System.out.println("-2-");
    DatabaseReference ref = FirebaseDatabase.getInstance()
            .getReference("/some_resource");
        ref.addListenerForSingleValueEvent(new ValueEventListener() {
          public void onDataChange(DataSnapshot dataSnapshot) {
              String res = (String) dataSnapshot.getValue();
                System.out.println(res);
          }
          public void onCancelled(DatabaseError error) {
          }
        });

}

pom.xml:

<dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-admin</artifactId>
        <version>6.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.common/google-collect -->
<dependency>
    <groupId>com.google.common</groupId>
    <artifactId>google-collect</artifactId>
    <version>0.5</version>
</dependency>

...

enter image description here

enter image description here

0 个答案:

没有答案