Я хочу загрузить фотографию в Google-Photo с помощью google-api-client. Вот мой код:
файл Gradle:
api 'com.google.api-client:google-api-client:1.26.0'
api 'com.google.api-client:google-api-client-android:1.26.0'
api 'io.grpc:grpc-okhttp:1.16.1'
api 'com.google.photos.library:google-photos-library-client:1.0.1'
api 'com.google.android.gms:play-services-auth:16.0.1'
api 'com.google.android.gms:play-services-drive:16.0.0'
Инициализация фото-клиента:
private fun initializePhotoClient(): PhotosLibraryClient? {
val token = authRepository.getAccessToken()
val credentials = googleAuth.getUserCredentials(token) ?: return null
val settings = PhotosLibrarySettings.newBuilder()
.setCredentialsProvider { credentials }.build()
return PhotosLibraryClient.initialize(settings)
}
uploadFile:
val fileName = localFileProvider.getFileName(uri)
val uploadRequest = UploadMediaItemRequest.newBuilder()
.setFileName(fileName)
.setDataFile(RandomAccessFile(uri, "r"))
.build()
val uploadResponse = photosLibraryClient.uploadMediaItem(uploadRequest)
uploadMediaItem
метод всегда возвращает ошибку, как показано ниже. Кто-нибудь знает, как это исправить? Пожалуйста, дайте мне подсказку.
10-27 22:05:47.881 22671-22767/com.smilebooth.easyshare E/AndroidRuntime: FATAL EXCEPTION: android_2
Process: com.smilebooth.easyshare, PID: 22671
java.lang.NoSuchMethodError: No static method catching(Lcom/google/common/util/concurrent/ListenableFuture;Ljava/lang/Class;Lcom/google/common/base/Function;)Lcom/google/common/util/concurrent/ListenableFuture; in class Lcom/google/common/util/concurrent/Futures; or its super classes (declaration of 'com.google.common.util.concurrent.Futures' appears in /data/app/com.smilebooth.easyshare-_OaEo0xawrKXOX90QnGu-Q==/split_lib_dependencies_apk.apk!classes2.dex)
at com.google.api.core.ApiFutures.catching(ApiFutures.java:77)
at com.google.photos.library.v1.upload.PhotosLibraryUploadUnaryCallable.futureCall(PhotosLibraryUploadUnaryCallable.java:50)
at com.google.photos.library.v1.upload.PhotosLibraryUploadUnaryCallable.futureCall(PhotosLibraryUploadUnaryCallable.java:31)
at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
at com.google.photos.library.v1.PhotosLibraryClient.uploadMediaItem(PhotosLibraryClient.java:125)
at com.smilebooth.data.repository.ShareDataRepository.uploadPhotoContent(ShareDataRepository.kt:201)
at com.smilebooth.data.repository.ShareDataRepository.share(ShareDataRepository.kt:104)
at com.smilebooth.domain.usecase.ShareUseCase$buildUseCaseObservable$1.subscribe(ShareUseCase.kt:21)
at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)
at io.reactivex.Observable.subscribe(Observable.java:12090)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:260)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
ОБНОВЛЕНО: Добавьте функцию, которая инициализирует photosLibraryClient как @Ricardo. Фото-клиент работает так, как я могу без проблем создать альбом