添加Google Photos API依赖后出现Duplicate Class错误求助
The Problem
You're hitting duplicate class conflicts after adding com.google.photos.library:google-photos-library-client:1.5.0 to your Android project. The error points to overlapping classes like com.google.api.Advice that exist in both proto-google-common-protos-1.17.0.jar (from Google Photos) and protolite-well-known-types-17.0.0-runtime.jar (from Firebase dependencies).
The Solution
This conflict happens because the Google Photos client pulls in proto-google-common-protos, which shares identical proto-generated classes with Firebase's protolite-well-known-types. Here's how to resolve it:
Exclude the conflicting dependency from Google Photos
Modify your Google Photos dependency entry in your module-levelbuild.gradleto exclude the duplicate library:implementation('com.google.photos.library:google-photos-library-client:1.5.0') { exclude group: 'com.google.api.grpc', module: 'proto-google-common-protos' }Verify the dependency tree (optional but recommended)
Run this command in your project's terminal to confirm the duplicate dependency is removed:./gradlew app:dependenciesSearch for
proto-google-common-protosin the output—you should no longer see it listed under the Google Photos dependency.Clean and rebuild your project
- Go to
Build > Clean Projectin Android Studio - Then run
Build > Rebuild Projectto ensure all changes take effect
- Go to
Why This Works
Firebase's protolite-well-known-types is a lightweight implementation of the common protobuf types, and it's fully compatible with the classes that Google Photos needs. By excluding the heavier proto-google-common-protos from the Google Photos dependency, we let the project use Firebase's version exclusively, eliminating the class conflict.
Bonus Tips
If you still run into duplicate class issues:
- Check other dependencies to see if any also pull in
proto-google-common-protos, and apply the same exclusion rule to them - Update your Firebase dependencies to the latest stable versions—newer releases often include dependency conflict fixes
内容的提问来源于stack exchange,提问作者Soumik Bhattacharjee

