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

升级Android Studio至3.1.2后出现org.tensorflow.Graph$Reference类型重复问题求助

Fixing "Program type already present: org.tensorflow.Graph$Reference" Error in Android Studio 3.1.2

Hey there! That duplicate class error is super common when multiple dependencies end up including the same TensorFlow code—let's walk through how to fix it step by step.

1. Track down the source of the duplicate dependency

First, we need to figure out which libraries are pulling in conflicting TensorFlow classes. Run this command in your project's terminal:

# For macOS/Linux
./gradlew app:dependencies

# For Windows
gradlew app:dependencies

Search the output for entries containing org.tensorflow—you'll likely see two different paths to the same class (one from your direct dependency, another from a third-party library you're using).

2. Exclude the duplicate TensorFlow module

Once you spot the culprit library, add an exclude rule to its dependency declaration to remove the conflicting TensorFlow code. For example, if com.example:image-processing-lib:2.0 is the troublemaker:

implementation('com.example:image-processing-lib:2.0') {
    exclude group: 'org.tensorflow'
}

3. Force a single TensorFlow version (for version conflicts)

If different dependencies are using mismatched TensorFlow versions, you can force all of them to use the same stable version. Add this to your project's root build.gradle file:

allprojects {
    configurations.all {
        resolutionStrategy.force 'org.tensorflow:tensorflow-android:1.13.1' // Replace with your preferred stable version
    }
}

4. Check your local libs folder

Your current config includes implementation fileTree(dir: 'libs', include: ['*.jar'])—double-check the libs directory for any TensorFlow-related .jar files. If you have one there and also a remote TensorFlow dependency, delete one of them to eliminate the duplicate.

5. Clean cache and rebuild

Sometimes stale cache can cause weird issues like this. Go to File > Invalidate Caches / Restart in Android Studio, then rebuild your project from scratch.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 08:38:47