升级Android Studio至3.1.2后出现org.tensorflow.Graph$Reference类型重复问题求助
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

