天天看點

Failed to resolve: com.android.support:appcompat-v7:29+

在Android Studio中,建立項目時,會報錯

ERROR: Failed to resolve: com.android.support:appcompat-v7:29.0.1

 。或者是

ERROR: Failed to resolve: com.android.support:appcompat-v7:29+

這是我的 

build.gradle

apply plugin: 'com.grpt.xxx'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.application.app"
        minSdkVersion 14
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:29.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
}
           

之是以發生如上錯誤,是因為

com.android.support:appcompat-v7:29.x.x

 不存在。

将替換 

implementation 'com.android.support:appcompat-v7:29.0.1'

為 :

implementation 'androidx.appcompat:appcompat:1.0.2'

不過,項目龐大最好用Android Studio自帶的選擇項功能轉移到AndroidX,自己手動替換上述,會導緻項目需要手動重新導入AndroidX的包替換之前appcompat-v7的包。

Support Library 28.0.0的穩定版本,适合在生産中使用。這将是android.support包裝下的最後一個功能版本,鼓勵開發人員遷移到AndroidX。

注意:随着Android 9.0(API級别28)的釋出,Jetpack包含了一個新版本的支援庫AndroidX。AndroidX庫包含現有的支援庫,還包含最新的Jetpack元件。

您可以繼續使用支援庫。曆史工件(那些版本為27和更早版本,并打包為android.support.*的工件)将在Google Maven上可用。但是,所有新的庫開發都将在AndroidX庫中進行。

我們建議在所有新項目中使用AndroidX庫。您還應該考慮将現有項目遷移到AndroidX。

可通過Android Studio自動将項目轉到AndroidX:選中項目app,右鍵選擇Refactor >> Refactor this >> migarat to AndroidX

Android studio如果找不到選擇項,則需要更新Android studio版本。