You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Firebase ML Kit的Android应用运行时出现重复类错误

Fixing Duplicate Class Errors with Firebase ML Kit Text Recognition

Hey there, let's sort out that duplicate class issue you're facing with your Android app's Firebase ML Kit setup!

What's Causing the Error?

The duplicate class messages you're seeing happen because the com.google.firebase:firebase-ml-vision:24.0.3 dependency pulls in play-services-vision:20.0.0, while another indirect dependency brings in an older play-services-vision-common:19.1.0—these two modules share overlapping internal classes, leading to the build conflict.

On top of that, the old firebase-ml-vision library is deprecated; Google now recommends using the standalone ML Kit libraries for text recognition, which are better maintained and less prone to version conflicts.

Replace the deprecated Firebase ML Vision dependency with the modern standalone ML Kit text recognition library, and let the Firebase BOM handle versioning to avoid conflicts.

Here's your updated build.gradle (Module: app) configuration:

apply plugin: 'com.google.gms.google-services'

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation platform('com.google.firebase:firebase-bom:26.1.0')
    implementation 'com.google.firebase:firebase-analytics'
    // Replace deprecated ML Vision with standalone text recognition library
    implementation 'com.google.mlkit:text-recognition:16.0.0'
}

Why This Works:

  • The standalone ML Kit libraries are decoupled from older Firebase dependencies, eliminating the overlapping class issue.
  • The Firebase BOM (com.google.firebase:firebase-bom) automatically syncs versions across all Firebase/ML Kit libraries, so you don't have to manually manage version numbers and risk conflicts.

If you need to stick with the deprecated firebase-ml-vision library for now, you can exclude the conflicting play-services-vision-common module from the ML Vision dependency:

apply plugin: 'com.google.gms.google-services'

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation platform('com.google.firebase:firebase-bom:26.1.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation ('com.google.firebase:firebase-ml-vision:24.0.3') {
        // Exclude the conflicting module
        exclude group: 'com.google.android.gms', module: 'play-services-vision-common'
    }
}

Note: This is a temporary fix—Google won't update the deprecated library anymore, so migrating to the new ML Kit is the long-term solution.

内容的提问来源于stack exchange,提问作者Mohamad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:25:00