New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState #50

Closed
pskd73 opened this Issue Jun 21, 2017 · 20 comments

Comments

Projects
None yet
@pskd73
Copy link

pskd73 commented Jun 21, 2017

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

@firebase-oss-bot

This comment has been minimized.

Copy link

firebase-oss-bot commented Jun 21, 2017

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@firebase-oss-bot

This comment has been minimized.

Copy link

firebase-oss-bot commented Jun 21, 2017

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@swftvsn

This comment has been minimized.

Copy link

swftvsn commented Jun 21, 2017

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.

@hiranya911

This comment has been minimized.

Copy link
Member

hiranya911 commented Jun 21, 2017

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.

@pskd73

This comment has been minimized.

Copy link

pskd73 commented Jun 24, 2017

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?

@pskd73

This comment has been minimized.

Copy link

pskd73 commented Jun 24, 2017

It was issue with google oauth library. I managed to fix it by removing old version of the google oauth library.

@pskd73 pskd73 closed this Jun 24, 2017

@hth

This comment has been minimized.

Copy link

hth commented Aug 6, 2017

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'
@cohenadair

This comment has been minimized.

Copy link

cohenadair commented Sep 24, 2017

@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.

@galcyurio

This comment has been minimized.

Copy link

galcyurio commented Nov 16, 2017

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>
@mituldreamworld

This comment has been minimized.

Copy link

mituldreamworld commented Dec 14, 2017

@hth Thanks for the solution.

@ZeyadAlma

This comment has been minimized.

Copy link

ZeyadAlma commented Jan 4, 2018

I'm having the same problem but the solution does not work for me
Java 8 Standard App Engine - Firebase Admin
Exception:

java.lang.NoSuchMethodError: 
    com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V`
    at com.google.firebase.FirebaseApp.checkNotDeleted (FirebaseApp.java:352)
    at com.google.firebase.FirebaseApp.getOptions (FirebaseApp.java:267)
    at com.google.firebase.FirebaseApp$TokenRefresher.<init> (FirebaseApp.java:434)
    at com.google.firebase.FirebaseApp$TokenRefresher$Factory.create (FirebaseApp.java:535)
    at com.google.firebase.FirebaseApp.<init> (FirebaseApp.java:113)
    at com.google.firebase.FirebaseApp.initializeApp (FirebaseApp.java:201)
    at com.google.firebase.FirebaseApp.initializeApp (FirebaseApp.java:188)
    at com.google.firebase.FirebaseApp.initializeApp (FirebaseApp.java:175)

Code:

    InputStream in = getServletConfig()..getResourceAsStream("/WEB-INF/PRIVATE_KEY_JSON.json");

    FirebaseOptions options = null;
    try {
        options = new FirebaseOptions.Builder()
                .setCredentials(GoogleCredentials.fromStream(in))
                .setDatabaseUrl("MyDBURL")
                .build();
    } catch (IOException e) {
        e.printStackTrace();
    }
    FirebaseApp app = FirebaseApp.initializeApp(options);

Dependency:

  appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.60'
  compile 'com.google.appengine.tools:appengine-gcs-client:
  compile ('com.google.firebase:firebase-admin:5.4.0'){
     exclude group: 'com.google.guava'
  }
  compile 'com.google.guava:guava:23.0'
  compile 'javax.servlet:servlet-api:2.5'
  compile 'com.google.code.gson:gson:2.8.2'
  compile 'com.googlecode.json-simple:json-simple:1.1.1'
  compile group: "com.twilio.sdk", name: "twilio", version: "7.11.+"
  compile 'com.sendgrid:sendgrid-java:4.1.1'
@779503982

This comment has been minimized.

Copy link

779503982 commented Jan 7, 2018

The solution didn't work for me either.

@zloyreznic

This comment has been minimized.

Copy link

zloyreznic commented Jan 11, 2018

try

			<exclusions>
				<exclusion>
					<groupId>com.google.guava</groupId>
					<artifactId>guava</artifactId>
				</exclusion>
				<exclusion>
					<groupId>com.google.guava</groupId>
					<artifactId>guava-jdk5</artifactId>
				</exclusion>
			</exclusions>
@779503982

This comment has been minimized.

Copy link

779503982 commented Jan 11, 2018

@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!

@ZeyadAlma

This comment has been minimized.

Copy link

ZeyadAlma commented Jan 12, 2018

@zloyreznic Thank you for replying, I excluded both Guava and Guava-jdk5. Still not working

@hiranya911 hiranya911 reopened this Jan 12, 2018

@hiranya911

This comment has been minimized.

Copy link
Member

hiranya911 commented Jan 12, 2018

While there's no guaranteed way to "fix" this, I think there may be a way to drastically reduce the chance of developers running into this. I will send a experimental PR shortly.

@hiranya911

This comment has been minimized.

Copy link
Member

hiranya911 commented Jan 12, 2018

@ZeyadAlma @779503982 I've attached a new firebase-admin binary with a potential fix at #125. Please check if that helps with this problem.

@779503982

This comment has been minimized.

Copy link

779503982 commented Jan 12, 2018

@hiranya911 Thank you! I think it worked for me. I just deleted all the exclusions and also the dependency on guava of newest version, that error didn't show up again. I can see two guava versions in Maven Dependencies in Eclipse, but without "no such method error".

Could you please help with another google project, this project won't work on google cloud: https://github.com/GoogleCloudPlatform/firebase-appengine-backend
Please see issue: project uses deprecated Managed VMs beta environment.
Well, it does work on local gcloud server, but the example is to deploy the project on google cloud. Thank you very much!

@hiranya911

This comment has been minimized.

Copy link
Member

hiranya911 commented Jan 12, 2018

@779503982 thanks for the feedback.

The issue with the other project is not really related to Admin SDK in anyway, but it seems it was fixed a few weeks ago: GoogleCloudPlatform/firebase-appengine-backend#8

You should follow up there.

@hiranya911

This comment has been minimized.

Copy link
Member

hiranya911 commented Jan 26, 2018

Fixed in #125.

@hiranya911 hiranya911 closed this Jan 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment