I want to add VertexAI from firebase to my Android project. I have an existing Firebase project where I have followed and completed all the steps to enable vertexAi.
I have imported firebase dependencies:
implementation(platform("com.google.firebase:firebase-bom:33.7.0"))
implementation("com.google.firebase:firebase-vertexai")
When even I call val gemini = Firebase.vertexAI.generativeModel("gemini-1.5-flash")
I get an error during runtime java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/plugins/HttpTimeout;
Yes its true, I have an other library, which is using io.ktor:ktor-client-android:3.0.2
so I have that included in my dependencies as well. I tried adding other ktor such as plugins, core ec... but always getting the same error.
I have tried to remove the orher library and clean/build with just firebase and vertex and still getting the same error.
When I run the vertex sample app it is working without any problem. I have tried to compare to the last symbol what are the differences between sample app and my app and found non related to ktor.
Where ever I look, everybody mentions, vertex ai on firebase is using ktor. But when I log app:dependencies
I don't see it in the tree under firebase. I found a github issue mentioning to downgrade ktor to 2.x.x, which I did and same result.
I there some funny little thing I have to include in my project, which would help me resolve this issue? Is there some totally out of context plugin/library, which I need to include resolve?
Exception at when using 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)
Exception at when using 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)
...which is calling HttpTimeout, which I have no problem using in my app code. Exception is always thrown inside vertexai.
In my case the solution is to add a code below to build.gradle.kts:
configurations.all {
resolutionStrategy.force("io.ktor:ktor-client-okhttp:2.3.2")
}
Here is you can find a version using in the SDK: https://github.com/google-gemini/generative-ai-android/blob/b5d2e5610d19522ad10e6dc7e98236689aaa3587/common/build.gradle.kts#L75. For now it looks like val ktorVersion = "2.3.2"
.