Android集成Firebase VertexAI遭遇NoClassDefFoundError问题求助
Firebase VertexAI集成时的NoClassDefFoundError问题
已完成Firebase项目中启用VertexAI的全部步骤,并导入以下依赖:
implementation(platform("com.google.firebase:firebase-bom:33.7.0")) implementation("com.google.firebase:firebase-vertexai")
但调用val gemini = Firebase.vertexAI.generativeModel("gemini-1.5-flash")时,运行时抛出错误:java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/plugins/HttpTimeout;
已尝试的操作:
- 项目原本包含
io.ktor:ktor-client-android:3.0.2,尝试添加Ktor相关插件、核心库均无效; - 移除该库仅保留Firebase和VertexAI依赖后,问题依旧;
- 对比官方VertexAI示例项目,未发现与Ktor相关的差异,且在依赖树中未看到Firebase引入Ktor;
- 将Ktor降级至2.x.x版本,仍出现相同错误。
不同Ktor版本下的异常信息:
使用Ktor 3.0.2时:
java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/plugins/HttpTimeout; at com.google.firebase.vertexai.common.APIController$client$1.invoke(APIController.kt:101)
使用Ktor 2.3.2时:
java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/plugins/HttpTimeout; at io.ktor.client.engine.okhttp.OkHttpEngine.<init>(OkHttpEngine.kt:40) at io.ktor.client.engine.okhttp.OkHttp.create(OkHttp.kt:31)
应用代码中直接使用HttpTimeout无问题,但异常始终在VertexAI内部抛出,请问是否有特殊配置或需额外引入的库可解决该问题?
内容的提问来源于stack exchange,提问作者parohy
相关产品推荐
相关产品推荐

