java - Firebase Firestore 在运行时错误时崩溃

标签 java android firebase android-gradle-plugin google-cloud-firestore

我有一个使用 Google Cloud Speech 和 Firebase 实时数据库的项目,随着项目的发展,我想添加 Google FireStore 功能。但是在编译依赖项后,我遇到了运行时错误:

Error:(458, 21) error: no suitable method found for 
intercept(GoogleCredentialsInterceptor)
method zzbc.intercept(List<zzl>) is not applicable
(argument mismatch; GoogleCredentialsInterceptor cannot be converted to List<zzl>)
method zzbc.intercept(zzl...) is not applicable
(varargs mismatch; GoogleCredentialsInterceptor cannot be converted to zzl)
method AbstractManagedChannelImplBuilder.intercept(List<zzl>) is not applicable
(argument mismatch; GoogleCredentialsInterceptor cannot be converted to List<zzl>)
method AbstractManagedChannelImplBuilder.intercept(zzl...) is not applicable
(varargs mismatch; GoogleCredentialsInterceptor cannot be converted to zzl)

当我尝试从 GCS 获取凭据时,会发生此错误。

 @Override
    protected void onPostExecute(AccessToken accessToken) {
        mAccessTokenTask = null;
        final ManagedChannel channel = new OkHttpChannelProvider()
                .builderForAddress(HOSTNAME, PORT)
                .nameResolverFactory(new DnsNameResolverProvider())
                .intercept(new GoogleCredentialsInterceptor(new GoogleCredentials(accessToken)
                        .createScoped(SCOPE)))
                .build();
        mApi = SpeechGrpc.newStub(channel);

        // Schedule access token refresh before it expires
        if (mHandler != null) {
            mHandler.postDelayed(mFetchAccessTokenRunnable,
                    Math.max(accessToken.getExpirationTime().getTime()
                            - System.currentTimeMillis()
                            - ACCESS_TOKEN_FETCH_MARGIN, ACCESS_TOKEN_EXPIRATION_TOLERANCE));
        }
    }
}

代码在这部分代码崩溃:

.intercept(new GoogleCredentialsInterceptor(new GoogleCredentials(accessToken).createScoped(SCOPE)))

我的依赖项:

  ext {
    //FirebaseUI Version    Firebase/Play Services Version
    //     3.1.0                    11.4.2
    supportLibraryVersion = '27.0.0'
    grpcVersion = '1.7.0'
    googlePlayVersion = '11.4.2'
    firebaseVersion = '11.4.2'
    fireUIVersion = '3.1.0'
    facebookVersion = '4.27.0'
    glideVersion = '4.3.0'
}

  ...
  compile fileTree(include: ['*.jar'], dir: 'libs')
compile "io.grpc:grpc-okhttp:$grpcVersion"
compile "io.grpc:grpc-protobuf-lite:$grpcVersion"
compile "io.grpc:grpc-stub:$grpcVersion"
compile('com.google.auth:google-auth-library-oauth2-http:0.7.1') {
    exclude module: 'httpclient'
}

// Support Libraries:
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.android.support:preference-v7:$supportLibraryVersion"
compile "com.android.support:design:$supportLibraryVersion"
compile "com.android.support:cardview-v7:$supportLibraryVersion"
compile "com.android.support:preference-v7:$supportLibraryVersion"
compile "com.google.android.gms:play-services-auth:$firebaseVersion"

// FirebaseUI for Firebase Auth

compile "com.google.android.gms:play-services-auth:$googlePlayVersion"
compile "com.google.firebase:firebase-database:$firebaseVersion"
compile "com.google.firebase:firebase-auth:$firebaseVersion"
compile "com.google.firebase:firebase-core:$firebaseVersion"
compile "com.google.firebase:firebase-firestore:$firebaseVersion"

compile "com.android.support:recyclerview-v7:$supportLibraryVersion"
compile "com.android.support:support-v4:$supportLibraryVersion"

compile 'com.firebaseui:firebase-ui-auth:3.1.0'
compile 'com.android.support.constraint:constraint-layout-solver:1.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'javax.annotation:javax.annotation-api:1.2'

  apply plugin: 'com.google.gms.google-services'

项目级别:

    buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
        classpath 'com.android.tools.build:gradle:3.1.0-alpha01'
        classpath 'com.google.gms:google-services:3.1.1'
    }


allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        maven { url "https://jitpack.io" }
        maven {
            url  "http://dl.bintray.com/ahmedrizwan/maven"
        }
        maven {
            url "http://dl.bintray.com/glomadrian/maven"
        }

        mavenCentral()
    }
}

如果我删除:

     // TRYED WITH compile 'com.google.firebase:firebase-firestore:11.4.2'
  compile 'com.firebaseui:firebase-ui-auth:3.1.0'

一切都很好!但我需要它来实现 Firestore 功能。

我启用了所有 API,并禁用了 Google 云数据存储。

Cloud Firestore and App Engine: You can't use both Cloud Firestore and Cloud Datastore in the same project, which might affect apps using App Engine. Try using Cloud Firestore with a different project.

最佳答案

很抱歉您遇到此问题,但 Firestore(当前)与外部 gRPC 不兼容,如此处所述:

Cloud Firestore with gRPC build error

11.8.0 版本修复了此问题。

关于java - Firebase Firestore 在运行时错误时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47076623/

相关文章:

java - 如何使base64图像字符串更短,Android?

angularjs - 如何保护 Firebase 应用程序免受无限循环的影响?

java - 在 Spring Controller 中使用 Callable 和 WebApplicationInitializer 获取 IllegalStateException

java - 算法逻辑

android - 在 Android 2.3.3 (Gingerbread) API 10 中使用 TLS 1.2/1.3 连接连接 HTTPS API

java - 从 Activity 中的异步任务获取值(value)

firebase - Flutter:我们如何在桌面应用程序中使用 Firebase 数据库

firebase - Firebase 自定义身份验证是否要求您管理 Web 客户端的刷新 token ?

java - Spring @Scheduler 执行了两次。我正在使用 spring security,如果我删除上下文参数 spring security 不起作用

Java、Gradle、CI 和指定内存使用限制