Issue
I am trying to connect to firestore through the firebase admin SDK. However, when I call:
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.build();
FirebaseApp.initializeApp(options);
I get the following exception: java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, java.lang.Object)'
I only get this exception when running the program through the jar file, it runs fine when compiled through NetBeans. I read online and it seems to be an issue with versions of the firebase admin SDK, but I am not sure which version to use and have tried multiple versions with the same error.
Maybe it is an error with the way I am bundling my dependencies in the jar file?
This is my build.gradle file:
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'application'
mainClassName = 'QMPAngola.Main'
repositories {
jcenter()
}
dependencies {
compile 'com.google.firebase:firebase-admin:5.9.0'
testCompile 'junit:junit:4.12'
}
configurations.all {
resolutionStrategy {
force 'com.google.guava:guava:30.1.1-jre'
}
}
jar {
manifest {
attributes "Main-Class": "QMPAngola.Main"
}
from { (configurations.runtime).collect {it.isDirectory() ? it : zipTree(it)} }
}
This is the full stacktrace:
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, java.lang.Object)'
at com.google.cloud.firestore.Query$ComparisonFilter.<init>(Query.java:137)
at com.google.cloud.firestore.Query.whereEqualTo(Query.java:423)
at com.google.cloud.firestore.Query.whereEqualTo(Query.java:401)
at QMPAngola.FirebaseUI.driverStart(FirebaseUI.java:315)
at QMPAngola.FirebaseUI.<init>(FirebaseUI.java:51)
at QMPAngola.Main$1.run(Main.java:36)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Solution
From my understanding com.google.firebase:firebase-admin
is using guava
as dependency.
From my understanding you override the transitive dependency to guava by
configurations.all {
resolutionStrategy {
force 'com.google.guava:guava:30.1.1-jre'
}
}
with a incompatible version.
I'd say you should remove that block or is there any reason why you added it?
Answered By - asbachb
Answer Checked By - Katrina (JavaFixing Volunteer)