firebase-admin-java: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState

Here is my code

FileInputStream serviceAccount = new FileInputStream("firebase.json");
		FirebaseOptions options = new FirebaseOptions.Builder()
			.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
			.setDatabaseUrl("https://xxxxx.firebaseio.com/")
			.build();
		FirebaseApp.initializeApp(options);
		FirebaseAuth.getInstance();

FirebaseAuth.getInstance(); causing the issue. The error log stack is here

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
	at com.google.firebase.FirebaseApp.checkNotDeleted(FirebaseApp.java:314)
	at com.google.firebase.FirebaseApp.getOptions(FirebaseApp.java:260)
	at com.google.firebase.auth.FirebaseAuth.<init>(FirebaseAuth.java:74)
	at com.google.firebase.auth.FirebaseAuth.<init>(FirebaseAuth.java:61)
	at com.google.firebase.auth.FirebaseAuth.<init>(FirebaseAuth.java:52)
	at com.google.firebase.auth.FirebaseAuth$FirebaseAuthService.<init>(FirebaseAuth.java:316)
	at com.google.firebase.auth.FirebaseAuth.getInstance(FirebaseAuth.java:98)
	at com.google.firebase.auth.FirebaseAuth.getInstance(FirebaseAuth.java:85)
	at com.datasignstech.lam.core.google.GoogleInterface.main(GoogleInterface.java:119)

I am not sure why I am getting the above error. I see the code and at FirebaseApp.java:314 it is passing 3 arguments, but in error it is showing only two arguments, which is not there in Preconditions. Kindly help me in this.

I am using firebase-admin sdk: 5.2.0 Jdk: 1.8.0 OS: Ubuntu 16.04

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (5 by maintainers)

Most upvoted comments

Code below should fix this issue.

compile ('com.google.firebase:firebase-admin:5.2.0') {
   exclude group: 'com.google.guava'
}
compile 'com.google.guava:guava:23.0'

maven solution example

<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>${firebase.version}</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>${guava.version}</version>
</dependency>

Yes, this happens when two version of Guava ends up in the classpath. Check the dependency tree and add an exclusion rule to the older version.

@zloyreznic Thank you very much for your reply. I appreciate it. After I added the routines galcyurio provided, I noticed there were still two versions of guava existed in the maven dependencies in Eclipse. So I right clicked the guava with lower version in “Maven Dependencies”, and select “Maven” – “Exclude Maven Artifact”, and this issue was thus figured out. Still, thank you very much!

Hi,

this is most likely wrong version of Guava. Check mvn dependency:tree or gradlew dependencies to find out what version you have.

iirc the version 20 and up of guava has that. However, many libraries depend on older version if you use google cloud stuff.

@hth Thank you! In my case I used to use Guava 20.0 as 23.0 requires Java 8 and I’m still on Java 7. Note that I used 20.0, but there may be newer versions that do not require Java 8.

Thanks @hiranya911 Now the above issue got fixed. But I am facing another issue now.

java.lang.NoSuchMethodError: com.google.firebase.auth.internal.FirebaseTokenVerifier.getIssuers()Ljava/util/Collection;
	at com.google.firebase.auth.internal.FirebaseTokenVerifier.verifyTokenAndSignature(FirebaseTokenVerifier.java:120)
	at com.google.firebase.auth.FirebaseAuth$2.then(FirebaseAuth.java:199)
	at com.google.firebase.auth.FirebaseAuth$2.then(FirebaseAuth.java:187)
	at com.google.firebase.tasks.ContinueWithCompletionListener$1.run(ContinueWithCompletionListener.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)

I am getting this error when I cann verifyIdToken() method. Can you/anybody help me in this?