Initializing Firebase Admin in App Engine standard Java

574 views
Skip to first unread message

Zeyad Almajed

unread,
Jan 2, 2018, 5:49:34 PM1/2/18
to Google App Engine

I'm trying to use Firebase Auth in App engine standard Java to verify tokens from Android.

However, when I try to initialize Firebase admin, I get an Exception.

here is the 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)

Most likely, because of conflict in Guava versions

here is my gradle:

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.60'
    compile 'com.google.appengine.tools:appengine-gcs-client:0.7'
    compile ('com.google.firebase:firebase-admin:5.7.0') {
        exclude group: 'com.google.guava'
    }
    compile 'com.google.guava:guava:23.0'
    compile 'javax.servlet:servlet-api:2.5'
}

Here is the code:

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

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


George (Cloud Platform Support)

unread,
Jan 3, 2018, 3:27:38 PM1/3/18
to Google App Engine
Hello Zeyad, 

Your "try" block seems to lack a line: ".setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/") ". For related details, you may read the "Initialize the SDK" sub-chapter of the "Add the Firebase Admin SDK to Your Server" online document. The build.gradle file should include the statement: 

"dependencies {
  compile 'com.google.firebase:firebase-admin:5.6.0'
}     "

Zeyad Almajed

unread,
Jan 3, 2018, 7:01:59 PM1/3/18
to Google App Engine
I Only use Firebase Auth, so no need to use database, however I've added it just in case
It doesn't work,
I tried to use the following:
"compile 'com.google.firebase:firebase-admin:5.6.0'"
and
"compile ('com.google.firebase:firebase-admin:5.6.0') {

exclude group: 'com.google.guava'
}
compile 'com.google.guava:guava:23.0'"
 and 5.7.0 and 5.4.0
none of them work

I'm using Java 8 standard app engine and stuck for a whole week

George (Cloud Platform Support)

unread,
Jan 5, 2018, 10:37:38 PM1/5/18
to Google App Engine
You are right about the two different versions of Guava that appear in the project class path. The Admin SDK imports Guava 20.0, and one of his dependencies (okhttp-eventsource) imports Guava 19.0. Basically, the transitive dependency on Guava 19.0 needs to be avoided. You can accomplish this in a way similar to what is indicated in the snippet below:

dependencies { 
  compile fileTree(dir: 'libs', include: ['*.jar']) 

  compile ('com.launchdarkly:okhttp-eventsource:1.3.0'){
    exclude group: "com.google.guava", module: "guava"
  }
  compile 'com.google.firebase:firebase-admin:4.1.7' 

For more Gradle specific info you may choose to read the "25.4.7. Excluding transitive dependencies" sub-chapter in the documentation. 

Zeyad Almajed

unread,
Jan 8, 2018, 11:58:07 AM1/8/18
to Google App Engine
it does not work, the same exception

George (Cloud Platform Support)

unread,
Jan 8, 2018, 8:45:50 PM1/8/18
to Google App Engine
Have you checked if the dependency of Guava 19.0 is still there? The proposed code needs to be adapted to your particular situation. 

Zeyad Almajed

unread,
Jan 12, 2018, 10:35:01 AM1/12/18
to Google App Engine
and How do I check that?

I'm looking for a solution.

George (Cloud Platform Support)

unread,
Jan 12, 2018, 11:54:02 PM1/12/18
to Google App Engine
You'll notice that the transitive dependency is gone as your exception should be gone. We'll examine the information received and come back to you shortly. Thank you for your patience!
Reply all
Reply to author
Forward
0 new messages