引入SharePoint依赖后Gradle构建失败:找不到android:attr/fontVariationSettings
看起来你遇到了两个关联的问题:support库版本冲突,以及由此引发的fontVariationSettings资源找不到错误。咱们一步步来解决:
问题根源分析
- 版本冲突:Gradle检测到
com.android.support库同时存在27.1.1和28.0.0-alpha1两个版本,这通常是因为你引入的某个第三方库(比如adal或sharepoint-services)内部依赖了更高版本的support库,和你手动声明的27.1.1版本冲突。 - 资源缺失:
fontVariationSettings是Android API 26(8.0)新增的属性,当依赖库混合不同版本的support库时,AAPT会找不到对应版本的资源定义,从而报错。
解决方案
方案1:强制统一所有support库版本到27.1.1
这个方案不需要升级你的compileSdk版本,只需强制Gradle使用你指定的27.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' } } } }
- 确保你的
compileSdkVersion和targetSdkVersion至少为27(这是appcompat-v7:27.1.1的最低要求):
android { compileSdkVersion 27 defaultConfig { targetSdkVersion 27 // 其他默认配置... } // 其他android配置... }
- 重新同步Gradle,构建项目。
方案2:升级到稳定的support库28.0.0版本
如果你的项目可以兼容更高的API级别,升级到稳定的28.0.0版本是更彻底的解决方式:
- 更新
compileSdkVersion和targetSdkVersion到28:
android { compileSdkVersion 28 defaultConfig { targetSdkVersion 28 // 其他默认配置... } // 其他android配置... }
- 更新所有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' }
- 重新同步Gradle并构建。
额外排查步骤
如果你想确认到底是哪个第三方库引入了28.0.0-alpha1的support库,可以在终端执行以下命令查看完整依赖树:
./gradlew app:dependencies
在输出中搜索com.android.support,找到带有28.0.0-alpha1的条目,就能定位到冲突的来源。
内容的提问来源于stack exchange,提问作者Rahul Deshmukh
相关产品推荐
相关产品推荐

