在build.gradle中添加以下內容就解決了
dependencies { implementation 'com.google.android.material:material:1.0.0' }
如果想創建項目時就默認添加了依賴的話,需要修改項目創建的生成模板
在Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidModule\root\build.gradle.ftl添加以上內容即可
dependencies { ${getConfigurationName("compile")} fileTree(dir: 'libs', include: ['*.jar']) <#if !improvedTestDeps> ${getConfigurationName("androidTestCompile")}('com.android.support.test.espresso:espresso-core:+', { exclude group: 'com.android.support', module: 'support-annotations' }) </#if> <@kt.addKotlinDependencies /> <#if isInstantApp||isDynamicFeature> <#if isBaseFeature> <#if monolithicModuleName?has_content> application project(':${monolithicModuleName}') <#else> // TODO: Add dependency to the main application. // application project(':app') </#if> <#else> implementation project(':${baseFeatureName}') </#if> <#else> <@shared.watchProjectDependencies/> implementation 'com.google.android.material:material:1.0.0' </#if> }