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

Facebook登录API集成Gradle报错:attr/font资源重复定义

Fixing "duplicate value for resource 'attr/font'" When Integrating Facebook Login API

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:dependencies
    

    Look for entries under com.android.support or androidx — 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's build.gradle file, add a configuration block to force all dependencies to use the same version of the conflicting libraries. For example, if your project uses version 28.0.0 of 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 root gradle.properties file and add these lines:

    android.useAndroidX=true
    android.enableJetifier=true
    

    Jetifier 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:36:54