У меня есть незанятый проект в Intellij, где я пытаюсь получить доступ к базе данных Firestore, следуя руководству https://firebase.google.com/docs/admin/setup, но оно выдает ClassNotFoundException для google-oauth2 GoogleCredentials и в FirebaseOptions $ Builder для google-api Utils.
Ниже приведен мой код.
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
GoogleCredentials googleCredentials = GoogleCredentials.fromStream(serviceAccount);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(googleCredentials)
.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
Но это вызывает исключение ClassNotFoundException для com / google / auth / oauth2 / GoogleCredentials
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.<init>(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
И писать это так:
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
Выдает исключение в FirebaseOptions $ Builder для утилит googleapis
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.<init>(FirebaseOptions.java:197)
at com.amazon.asksdk.roomservice.data.DatabaseInitializer.initialize(DatabaseInitializer.java:45)
at com.amazon.asksdk.roomservice.data.TasksDAO.<init>(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
build.gradle
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'
}
Как мне решить эту проблему, поскольку gradle должен сам позаботиться о правильных зависимостях? Я попытался явно добавить следующее, но это не сработало:
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'
Я также вижу это во внешних библиотеках. Я пытаюсь запустить этот проект с помощью AWS lambda, поэтому я загружаю jar в lambda, чтобы в итоге запустить это.