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

引入SharePoint依赖后Gradle构建失败:找不到android:attr/fontVariationSettings

解决SharePoint客户端构建的Gradle依赖冲突与资源缺失问题

看起来你遇到了两个关联的问题:support库版本冲突,以及由此引发的fontVariationSettings资源找不到错误。咱们一步步来解决:

问题根源分析

  1. 版本冲突:Gradle检测到com.android.support库同时存在27.1.1和28.0.0-alpha1两个版本,这通常是因为你引入的某个第三方库(比如adal或sharepoint-services)内部依赖了更高版本的support库,和你手动声明的27.1.1版本冲突。
  2. 资源缺失:fontVariationSettings是Android API 26(8.0)新增的属性,当依赖库混合不同版本的support库时,AAPT会找不到对应版本的资源定义,从而报错。

解决方案

方案1:强制统一所有support库版本到27.1.1

这个方案不需要升级你的compileSdk版本,只需强制Gradle使用你指定的27.1.1版本覆盖所有冲突的依赖:

  1. 在你的Module级build.gradle中,在android代码块之后添加以下配置:
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            // 排除multidex,避免影响多 dex 配置
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '27.1.1'
            }
        }
    }
}
  1. 确保你的compileSdkVersion和targetSdkVersion至少为27(这是appcompat-v7:27.1.1的最低要求):
android {
    compileSdkVersion 27
    defaultConfig {
        targetSdkVersion 27
        // 其他默认配置...
    }
    // 其他android配置...
}
  1. 重新同步Gradle,构建项目。

方案2:升级到稳定的support库28.0.0版本

如果你的项目可以兼容更高的API级别,升级到稳定的28.0.0版本是更彻底的解决方式:

  1. 更新compileSdkVersion和targetSdkVersion到28:
android {
    compileSdkVersion 28
    defaultConfig {
        targetSdkVersion 28
        // 其他默认配置...
    }
    // 其他android配置...
}
  1. 更新所有support相关依赖到28.0.0版本,同时升级constraint-layout到兼容版本:
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    api 'com.microsoft.aad:adal:2.0.4-alpha'
    api 'com.microsoft.services:sharepoint-services:1.0.0@aar'
    api 'com.microsoft.services.orc:orc-android:1.3.1'
    api 'com.google.guava:guava:25.1-android'
}
  1. 重新同步Gradle并构建。

额外排查步骤

如果你想确认到底是哪个第三方库引入了28.0.0-alpha1的support库,可以在终端执行以下命令查看完整依赖树:

./gradlew app:dependencies

在输出中搜索com.android.support,找到带有28.0.0-alpha1的条目,就能定位到冲突的来源。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:42:51