title: Firestore ClassNotFoundException: com.google.auth.oauth2.GoogleCredentials and com/google/api/client/googleapis/util/Utils
body: <p>I have a gradle project in Intellij where I am trying to access the Firestore database by following the guide <a href="https://firebase.google.com/docs/admin/setup" rel="nofollow noreferrer">https://firebase.google.com/docs/admin/setup</a> but it throws ClassNotFoundException for google-oauth2 GoogleCredentials and in FirebaseOptions$Builder for google-api Utils. </p>
  
  <p>Following is my code.</p>
  
  <pre><code>FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
  GoogleCredentials googleCredentials = GoogleCredentials.fromStream(serviceAccount);
  FirebaseOptions options = new FirebaseOptions.Builder()
      .setCredentials(googleCredentials)
      .setDatabaseUrl("https://&lt;DATABASE_NAME&gt;.firebaseio.com/")
      .build();
  
  FirebaseApp.initializeApp(options);
  </code></pre>
  
  <p>But that throws ClassNotFoundException for com/google/auth/oauth2/GoogleCredentials</p>
  
  <pre><code>com/google/auth/oauth2/GoogleCredentials: java.lang.NoClassDefFoundError
  java.lang.NoClassDefFoundError: com/google/auth/oauth2/GoogleCredentials
  at com.amazon.asksdk.roomservice.data.DatabaseInitializer.initialize(DatabaseInitializer.java:36)
  at com.amazon.asksdk.roomservice.data.TasksDAO.&lt;init&gt;(TasksDAO.java:28)
  at com.amazon.asksdk.roomservice.RoomServiceSpeechlet.onSessionStarted(RoomServiceSpeechlet.java:54)
  at com.amazon.speech.speechlet.SpeechletRequestDispatcher.dispatchSpeechletCall(SpeechletRequestDispatcher.java:112)
  at com.amazon.speech.speechlet.SpeechletRequestHandler.internalHandleSpeechletCall(SpeechletRequestHandler.java:152)
  at com.amazon.speech.speechlet.SpeechletRequestHandler.handleSpeechletCall(SpeechletRequestHandler.java:115)
  at com.amazon.speech.speechlet.lambda.SpeechletRequestStreamHandler.handleRequest(SpeechletRequestStreamHandler.java:89)
  Caused by: java.lang.ClassNotFoundException: com.google.auth.oauth2.GoogleCredentials
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 7 more
  </code></pre>
  
  <p>And writing it like this:</p>
  
  <pre><code>FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
  
  FirebaseOptions options = new FirebaseOptions.Builder()
      .setCredentials(GoogleCredentials.fromStream(serviceAccount))
      .setDatabaseUrl("https://&lt;DATABASE_NAME&gt;.firebaseio.com/")
      .build();
  
  FirebaseApp.initializeApp(options);
  </code></pre>
  
  <p>Throws exception in FirebaseOptions$Builder for googleapis Utils</p>
  
  <pre><code>com/google/api/client/googleapis/util/Utils: java.lang.NoClassDefFoundError
  java.lang.NoClassDefFoundError: com/google/api/client/googleapis/util/Utils
  at com.google.firebase.FirebaseOptions$Builder.&lt;init&gt;(FirebaseOptions.java:197)
  at com.amazon.asksdk.roomservice.data.DatabaseInitializer.initialize(DatabaseInitializer.java:45)
  at com.amazon.asksdk.roomservice.data.TasksDAO.&lt;init&gt;(TasksDAO.java:28)
  at com.amazon.asksdk.roomservice.RoomServiceSpeechlet.onSessionStarted(RoomServiceSpeechlet.java:54)
  at com.amazon.speech.speechlet.SpeechletRequestDispatcher.dispatchSpeechletCall(SpeechletRequestDispatcher.java:112)
  at com.amazon.speech.speechlet.SpeechletRequestHandler.internalHandleSpeechletCall(SpeechletRequestHandler.java:152)
  at com.amazon.speech.speechlet.SpeechletRequestHandler.handleSpeechletCall(SpeechletRequestHandler.java:115)
  at com.amazon.speech.speechlet.lambda.SpeechletRequestStreamHandler.handleRequest(SpeechletRequestStreamHandler.java:89)
  Caused by: java.lang.ClassNotFoundException: com.google.api.client.googleapis.util.Utils
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 8 more
  </code></pre>
  
  <p>build.gradle</p>
  
  <pre><code>dependencies {
      compile 'com.amazon.alexa:alexa-skills-kit:1.5.0'
      compile 'com.amazonaws:aws-lambda-java-core:1.0.0'
      compile 'com.amazonaws:aws-java-sdk-dynamodb:1.9.40'
      compile 'com.amazonaws:aws-lambda-java-log4j:1.0.0'
      implementation 'com.google.firebase:firebase-admin:6.0.0'
  
      compile 'log4j:log4j:1.2.17'
      compile 'org.apache.commons:commons-lang3:3.3.2'
      compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
      compile 'org.eclipse.jetty:jetty-server:9.0.6.v20130930'
      compile 'org.eclipse.jetty:jetty-servlet:9.0.6.v20130930'
      compile 'org.slf4j:slf4j-api:1.7.10'
  }
  </code></pre>
  
  <p>How do I resolve this since gradle should be taking care of the correct dependencies by itself? I have tried explicitly adding the following but that didn't work:</p>
  
  <pre><code>compile 'com.google.oauth-client:google-oauth-client:1.23.0'
  compile 'com.google.oauth-client:google-oauth-client-servlet:1.23.0'
  compile 'com.google.oauth-client:google-oauth-client-appengine:1.23.0'
  compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
  </code></pre>
  
  <p>I also see these in the External Libraries. I am trying to run this project by AWS lambda, so I upload the jar to lambda to eventually run this.</p>