Gradle无法编译新版Material库,报资源未找到错误求解决
解决Material Design库依赖同步时的
fontVariationSettings和ttcindex错误 嘿,这个问题我之前也碰到过!根源是你用的com.google.android.material:material:1.0.0-alpha1属于Material Components库的早期预览版本,它依赖了Android 9.0(API Level 28)才引入的fontVariationSettings和ttcindex属性,但你的项目当前的compileSdkVersion是27,所以Gradle找不到这些资源,就抛出了错误。
下面是具体的修复步骤:
第一步:升级编译和目标SDK版本
在你的Module级别build.gradle中,把compileSdkVersion和targetSdkVersion都改成28:android { compileSdkVersion 28 defaultConfig { // ...其他配置不变 targetSdkVersion 28 // ...其他配置不变 } // ...其他配置不变 }第二步:更新Support库版本
Material Components早期版本和Android Support库28.x.x兼容,所以把你的appcompat-v7依赖升级到28.0.0:implementation 'com.android.support:appcompat-v7:28.0.0'第三步:统一依赖关键字(可选但推荐)
Gradle 3.0及以上版本推荐使用implementation代替旧的compile关键字,所以把Material库的依赖声明改成:implementation 'com.google.android.material:material:1.0.0-alpha1'
修改后的完整build.gradle代码如下:
apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "rockthesport.com.pruebasmaterial" minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.0' implementation 'com.google.android.material:material:1.0.0-alpha1' 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' }
最后再提个小建议:如果项目允许的话,尽量升级到更稳定的Material Components版本(比如1.4.0或更高),Alpha版本不仅bug多,后续的稳定版本还修复了很多兼容性问题,当然升级时要注意对应版本要求的compileSdkVersion哦。
内容的提问来源于stack exchange,提问作者tornic
相关产品推荐
相关产品推荐

