gpt4 book ai didi

android - DialogFlow Android SDK需要grpc-okhttp,但添加它会导致Socket IO CLient崩溃

转载 作者:行者123 更新时间:2023-12-02 13:41:44 27 4
gpt4 key购买 nike

环境细节
DialogFlow Android SDK v2.1.0的问题
重现步骤

  • 我已经使用DialogFlow在Android应用中实现了聊天机器人。我使用gradle实现导入了DialogFlow sdk。
  • 我崩溃了,说java.lang.NoSuchFieldError:类Lio / grpc / internal / GrpcUtil中没有Z类型的静态字段IS_RESTRICTED_APPENGINE
  • 根据我在Google搜索中解决此问题的搜索结果,我必须添加io.grpc:grpc-okhttp sdk。因此,我添加了它,此问题已解决,但又出现了一个问题。
  • 我的Android应用程序项目还具有Socket IO Client。当我初始化套接字客户端时,出现崩溃,提示没有虚拟方法callEngineGetConnection(Lcom / squareup / okhttp / Call;)Lcom / squareup / okhttp / Connection;在Lcom / squareup / okhttp / internal / Internal类中;
  • 如果我删除grpc-okhttp,那么Socket工作正常。

  • 代码示例
    如果您想测试一下,此代码可以重现该问题
    套接字初始化
    val socket = IO.socket("URL_HERE")
    socket.connect()
    DialogFlow初始化
    val stream = resources.openRawResource(R.raw.credentials)
    val credentials = GoogleCredentials.fromStream(stream)
    val projectId = (credentials as ServiceAccountCredentials).projectId

    val settingsBuilder = SessionsSettings.newBuilder()
    val sessionsSettings = settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build()
    val sessionsClient = SessionsClient.create(sessionsSettings) //This line causes the crash
    val session = SessionName.of(projectId, UUID.randomUUID().toString())
    这是我的build.gradle
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'com.google.firebase.crashlytics'
    apply plugin: 'kotlin-kapt'
    apply plugin: 'dagger.hilt.android.plugin'

    android {
    compileSdkVersion 30
    buildToolsVersion "29.0.3"

    defaultConfig {
    applicationId "com.identiygroup.career"
    minSdkVersion 23
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    buildConfigField("String", "googleApiKey", googleApiKey)
    }

    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    }
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/INDEX.LIST'
    exclude("META-INF/*.kotlin_module")
    }
    }

    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.0'
    implementation 'androidx.navigation:navigation-ui:2.3.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

    //firebase
    implementation 'com.google.firebase:firebase-auth:19.3.1'
    implementation 'com.google.firebase:firebase-core:17.4.3'

    //Crashlytics
    implementation 'com.google.firebase:firebase-crashlytics:17.1.0'

    //CarouselView
    implementation 'com.synnapps:carouselview:0.1.4'

    //exo-player
    implementation 'com.google.android.exoplayer:exoplayer:2.11.1'

    //PDF
    implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    implementation files('../libs/YouTubeAndroidPlayerApi.jar')

    implementation 'com.google.firebase:firebase-firestore:21.4.3'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation "androidx.core:core-ktx:1.3.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    //Navigation drawer
    implementation 'com.mikepenz:materialdrawer:7.0.0'

    implementation 'com.github.bassaer:chatmessageview:2.0.1'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation ('com.github.nkzawa:socket.io-client:0.6.0')

    //Dagger
    implementation 'com.google.dagger:hilt-android:2.28-alpha'
    kapt 'com.google.dagger:hilt-android-compiler:2.28-alpha'
    implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha01'
    kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha01'

    //Retrofit
    implementation ('com.squareup.retrofit2:retrofit:2.9.0')
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:4.7.2'

    //RecyclerView
    implementation 'androidx.recyclerview:recyclerview:1.1.0'

    // DialogFlow
    implementation ('com.google.cloud:google-cloud-dialogflow:2.1.0') {
    exclude group: "com.google.code.findbugs"
    exclude group: "javax.annotation"
    }
    implementation ('io.grpc:grpc-okhttp:1.29.0')
    }

    configurations.implementation.exclude(group: 'com.google.firebase', module: 'protolite-well-known-types')
    configurations.implementation.exclude(group: 'com.google.protobuf',module: 'protobuf-javalite')
    configurations.implementation.exclude(group: 'com.google.protobuf',module: 'protobuf-lite')
    configurations.implementation.exclude(group: 'com.google.code.findbugs', module: 'annotations')
    repositories {
    mavenCentral()
    }

    堆栈跟踪
    添加grpc时


    2020-07-01 22:59:15.216 6416-6668/com.identiygroup.career E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
    Process: com.identiygroup.career, PID: 6416
    java.lang.NoSuchMethodError: No virtual method callEngineGetConnection(Lcom/squareup/okhttp/Call;)Lcom/squareup/okhttp/Connection; in class Lcom/squareup/okhttp/internal/Internal; or its super classes (declaration of 'com.squareup.okhttp.internal.Internal' appears in /data/app/com.identiygroup.career-A85sKgM7VblLOhTeCZWZzQ==/base.apk!classes4.dex)
    at com.squareup.okhttp.ws.WebSocketCall.createWebSocket(WebSocketCall.java:154)
    at com.squareup.okhttp.ws.WebSocketCall.access$000(WebSocketCall.java:42)
    at com.squareup.okhttp.ws.WebSocketCall$1.onResponse(WebSocketCall.java:102)
    at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
    at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
    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:919)
    未添加grpc时
    2020-07-01 23:03:03.749 7633-7633/com.identiygroup.career E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.identiygroup.career, PID: 7633
    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.identiygroup.career-iEEqTKViLiYphc8hCE-Q8w==/base.apk!classes5.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 com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:314)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.access$1600(InstantiatingGrpcChannelProvider.java:71)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider$1.createSingleChannel(InstantiatingGrpcChannelProvider.java:210)
    at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:72)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:217)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:200)
    at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:156)
    at com.google.cloud.dialogflow.v2.stub.GrpcSessionsStub.create(GrpcSessionsStub.java:78)
    at com.google.cloud.dialogflow.v2.stub.SessionsStubSettings.createStub(SessionsStubSettings.java:108)
    at com.google.cloud.dialogflow.v2.SessionsClient.<init>(SessionsClient.java:132)
    at com.google.cloud.dialogflow.v2.SessionsClient.create(SessionsClient.java:114)
    at com.identiygroup.career.ChatActivity.onCreate(ChatActivity.kt:141)
    at android.app.Activity.performCreate(Activity.java:7826)
    at android.app.Activity.performCreate(Activity.java:7815)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1318)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3355)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3519)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2126)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:7709)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

    以下任何其他信息
    简而言之,如果未添加grpc,则对话框流崩溃。如果添加了grpc,则Socket崩溃。

    最佳答案

    升级到最新的SocketIO客户端。它将使用与gRPC不冲突的okhttp3 API。每当遇到此类问题时,也请考虑升级依赖项。

    关于android - DialogFlow Android SDK需要grpc-okhttp,但添加它会导致Socket IO CLient崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62682907/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com