Facebook登录API集成Gradle报错:attr/font资源重复定义
Hey there, let's work through this duplicate resource error you're facing after adding the Facebook Login API dependency. This is a super common conflict issue, so here's a step-by-step breakdown to resolve it:
First, pinpoint the conflicting dependencies
The error happens because the Facebook SDK is pulling in an older version of Android Support Libraries (or AndroidX equivalents) that clashes with the versions your project already uses. To see exactly which dependencies are causing the problem, run this command in your project's root directory:# For macOS/Linux ./gradlew app:dependencies # For Windows gradlew.bat app:dependenciesLook for entries under
com.android.supportorandroidx— you'll likely spot mismatched versions between your project's dependencies and the ones the Facebook SDK is requesting.Force a unified dependency version
In your app module'sbuild.gradlefile, add a configuration block to force all dependencies to use the same version of the conflicting libraries. For example, if your project uses version28.0.0of the Support Libraries, add this:configurations.all { resolutionStrategy { force 'com.android.support:appcompat-v7:28.0.0' force 'com.android.support:design:28.0.0' // Add other conflicting support libraries here (e.g., cardview, recyclerview) } }This tells Gradle to ignore the version specified by the Facebook SDK and use your project's preferred version instead.
Fix AndroidX vs. Support Library mixing
If your project has migrated to AndroidX but the Facebook SDK still relies on old Support Libraries, enable Jetifier to auto-convert those dependencies. Open your project's rootgradle.propertiesfile and add these lines:android.useAndroidX=true android.enableJetifier=trueJetifier will automatically rewrite the Facebook SDK's dependencies to use AndroidX equivalents, eliminating the resource conflict.
Clean and rebuild your project
No matter which fix you use, always run Build → Clean Project followed by Build → Rebuild Project in Android Studio. This clears out cached build files and ensures your new dependency configuration takes effect.
Note: The uneditable values.xml file you're seeing belongs to one of the dependency libraries (not your project), so you can't modify it directly — the fixes above work around the conflict instead.
内容的提问来源于stack exchange,提问作者Mathieu

