Problem I’m developing an Android app that uses both Google’s Gemini API (which depends on Ktor 2.x) and Supabase SDK (which requires Ktor 3.x). When including both libraries, I encounter class resolution errors due to conflicting Ktor versions.
Environment Android Studio Meerkat | 2024.3.1
Kotlin 1.9.x
Jetpack Compose
Hilt for DI
Target SDK 35
Error Details The app crashes with alternating errors:
Supabase-related error:
java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/HttpClientJvmKt;
at io.github.jan.supabasework.KtorSupabaseHttpClient.\<init\>(KtorSupabaseHttpClient.kt:55)
Gemini-related error:
java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/plugins/HttpTimeout;
at io.ktor.client.engine.okhttp.OkHttpEngine.<init>(OkHttpEngine.kt:40)
at com.google.ai.client.generativeaimon.APIController.<init>
Dependencies (build.gradle.kts) kotlin Copy // Supabase SDK (Ktor 3.x) :
implementation(libs.supabase.auth)
implementation(libs.supabase.postgrest)
implementation(libs.supabase.realtime)
implementation(libs.supabase.storage)
implementation(libs.supabase.functions)
// Gemini API (Ktor 2.x)
implementation(libs.generativeai)
// Explicit Ktor dependencies
implementation(libs.ktor.client.android)
Attempted Solutions Excluded Ktor from Gemini in build gradle.kts
implementation(libs.generativeai) {
exclude(group = "io.ktor")
}
Added explicit Ktor versions:
implementation("io.ktor:ktor-client-core:3.1.0")
implementation("io.ktor:ktor-client-okhttp:3.1.0")
// Also tried mixing versions (failed)
implementation("io.ktor:ktor-client-plugins:2.3.7")
Adjusted packagingOptions:
packaging {
resources {
pickFirsts.add("META-INF/INDEX.LIST")
pickFirsts.add("META-INF/ioty.versions.properties")
excludes.add("META-INF/*.kotlin_module")
}
}
None resolved the conflict.
Question How can I resolve this dependency conflict to use both Supabase (Ktor 3.x) and Gemini API (Ktor 2.x) in the same Android app? Is there a safe way to handle major version mismatches for Ktor?