今天導入從github上下載的一個項目,報了ERROR: Failed to resolve: androidx.appcompat:appcompat:1.1.0 這樣一個錯誤,從網上搜問題,大部分緣由是一、將1.1.0改成1.0.2,二、sdk compileSdkVersion buildToolsVersion問題。android
我這邊的報錯確不是以上緣由,而後看下appcompat的相關api,才找到了緣由git
聲明依賴項
要添加 Appcompat 的依賴項,您必須將 Google Maven 代碼庫添加到項目中。請閱讀 Google 的 Maven 代碼庫瞭解詳情。github
在應用或模塊的 build.gradle
文件中添加所需工件的依賴項:api
dependencies { def appcompat_version = "1.2.0" implementation "androidx.appcompat:appcompat:$appcompat_version" // For loading and tinting drawables on older versions of the platform implementation "androidx.appcompat:appcompat-resources:$appcompat_version" }
注意:必須將Google Maven 代碼庫添加到項目中,而後try again,編譯經過。app
allprojects { repositories { google() // If you're using a version of Gradle lower than 4.1, you must instead use: // maven { // url 'https://maven.google.com' // } // An alternative URL is 'https://dl.google.com/dl/android/maven2/' } }