firebase 在LiogrpcinternalGrpcUtil类中没有Z类型的静态字段IS_RESTRICTED_APPENGINE;或其超类中没有IS_RESTRICTED_APPENGINE。

问题描述 投票:0回答:1

这次使用GCP做项目时,在使用Firebase完成代码后,在添加云视界时发生了错误.因此,通过异常处理防止了依赖碰撞,但又发生了另一个错误。错误内容如下。

项目Build.gradle]

buildscript {
repositories {
    jcenter()
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}

dependencies {
    classpath 'com.android.tools.build:gradle:3.5.3'
    classpath 'com.google.gms:google-services:4.3.3'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
}
allprojects {
repositories {
    jcenter()
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

[app Build.gradle]

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion '28.0.3'
packagingOptions{}

defaultConfig {
    applicationId "com.example.voca"
    minSdkVersion 21
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/INDEX.LIST'
    exclude 'build-data.properties'
}
configurations {
    implementation.exclude module:'protolite-well-known-types'
    //implementation.exclude module:'proto-google-comon-protos'
    //implementation.exclude group:'com.google.guava'
    //implementation.exclude module:'protobuf-java'
    implementation.exclude module:'protobuf-javalite'
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:appcompat-v7:29.0.0'
implementation 'com.google.cloud:google-cloud-vision:1.99.3'
implementation 'com.android.support:design:29.0.0'
implementation('com.google.api-client:google-api-client-android:1.30.9')
implementation('com.google.http-client:google-http-client-gson:1.35.0')
//{OR}
//파이어 베이스
implementation('com.google.firebase:firebase-core:17.4.0')
implementation('com.google.firebase:firebase-database:18.0.0')
implementation('com.google.firebase:firebase-firestore:20.0.0')
implementation('com.google.capillary:lib-android:1.0.0', {
    exclude group: 'com.google.protobuf', module: 'protobuf-java'
})

}

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.voca, PID: 24074
java.lang.RuntimeException: Internal error in Firestore (19.0.2).
    at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$5(com.google.firebase:firebase-firestore@@19.0.2:379)
    at com.google.firebase.firestore.util.AsyncQueue$$Lambda$5.run(Unknown Source:2)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: java.lang.NoSuchFieldError: No static field IS_RESTRICTED_APPENGINE of type Z in class Lio/grpc/internal/GrpcUtil; or its superclasses (declaration of 'io.grpc.internal.GrpcUtil' appears in /data/app/com.example.voca-PC8_IVzX02rxZmfGRpj9gQ==/base.apk!classes4.dex)
    at io.grpc.okhttp.OkHttpChannelBuilder.createSslSocketFactory(OkHttpChannelBuilder.java:451)
    at io.grpc.okhttp.OkHttpChannelBuilder.buildTransportFactory(OkHttpChannelBuilder.java:418)
    at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:513)
    at io.grpc.android.AndroidChannelBuilder.build(AndroidChannelBuilder.java:176)
    at com.google.firebase.firestore.remote.Datastore.<init>(com.google.firebase:firebase-firestore@@19.0.2:131)
    at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore@@19.0.2:261)
    at com.google.firebase.firestore.core.FirestoreClient.lambda$new$2(com.google.firebase:firebase-firestore@@19.0.2:117)
    at com.google.firebase.firestore.core.FirestoreClient$$Lambda$2.run(Unknown Source:8)
    at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$4(com.google.firebase:firebase-firestore@@19.0.2:311)
    at com.google.firebase.firestore.util.AsyncQueue$$Lambda$4.call(Unknown Source:2)
    at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$3(com.google.firebase:firebase-firestore@@19.0.2:287)
    at com.google.firebase.firestore.util.AsyncQueue$$Lambda$3.run(Unknown Source:4)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at com.google.firebase.firestore.util.AsyncQueue$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@19.0.2:205)
    at java.lang.Thread.run(Thread.java:764)

如何处理这个错误?请回答:(

android google-cloud-platform grpc dependency-management
1个回答
1
投票

问题是 grpc-okhttp 的版本来说太老了。grpc-core 正在使用。版本应该匹配。

您可以通过运行 gradle dependencies --configuration releaseRuntimeClasspath:

...
+--- com.google.firebase:firebase-firestore:20.0.0
|    +--- androidx.annotation:annotation:1.0.0 -> 1.1.0
|    +--- androidx.fragment:fragment:1.0.0 (*)
|    +--- com.google.android.gms:play-services-base:17.0.0 (*)
|    +--- com.google.android.gms:play-services-basement:17.0.0 (*)
|    +--- com.google.android.gms:play-services-tasks:17.0.0 (*)
|    +--- com.google.firebase:firebase-auth-interop:18.0.0 (*)
|    +--- com.google.firebase:firebase-common:18.0.0 -> 19.3.0 (*)
|    +--- com.google.firebase:firebase-database-collection:17.0.0
|    +--- com.google.firebase:protolite-well-known-types:17.0.0
|    |    \--- com.google.protobuf:protobuf-lite:3.0.1
|    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    +--- com.squareup.okhttp:okhttp:2.7.5
|    |    \--- com.squareup.okio:okio:1.6.0 -> 1.13.0
|    +--- io.grpc:grpc-android:1.21.0
|    |    \--- io.grpc:grpc-core:[1.21.0] -> 1.28.1 (*)
|    +--- io.grpc:grpc-okhttp:1.21.0
|    |    +--- io.grpc:grpc-core:[1.21.0] -> 1.28.1 (*)
|    |    +--- com.squareup.okhttp:okhttp:2.5.0 -> 2.7.5 (*)
|    |    \--- com.squareup.okio:okio:1.13.0
|    +--- io.grpc:grpc-protobuf-lite:1.21.0 -> 1.28.1 (*)
|    \--- io.grpc:grpc-stub:1.21.0 -> 1.28.1 (*)
...

所以 com.google.firebase:firebase-firestore 正在拉拢 io.grpc:grpc-android:1.21.0io.grpc:grpc-okhttp:1.21.0io.grpc:grpc-core 正在从1.21.0升级到1.28.1。该 [] 左右 [1.21.0] 意思是说,该版本 必须[1.21.0]但Gradle不尊重它。

修复方法是将 grpc-okhttp (和 grpc-android). 有两种方法。

// individually
dependencies {
  implementation 'io.grpc:grpc-android:1.28.1'
  implementation 'io.grpc:grpc-okhttp:1.28.1'
}

// or with a BOM
dependencies {
  implementation platform('io.grpc:grpc-bom:1.28.1')
}
© www.soinside.com 2019 - 2024. All rights reserved.