Android Studio 一直拒绝解析 com.android.support:appcompat-v7:29.0.1

Android Studio keeps refusing to resolve com.android.support:appcompat-v7:29.0.1

我已经提到了 this 话题,但它没有解决我的问题。

我不断收到错误消息: ERROR: Failed to resolve: com.android.support:appcompat-v7:29.0.1 每次我尝试刷新 Android Studio 时 Gradle。

这是我的 build.gradle

apply plugin: 'com.android.application'

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'
}

我该如何修复它,是否有一个网站列出了所有 android 模块的所有版本?我自己找不到。

谢谢。

没有 29 的支持库你必须使用 androidx 新开发的支持库包

来自 Docs

This is the stable release of Support Library 28.0.0 and is suitable for use in production. This will be the last feature release under the android.support packaging, and developers are encouraged to migrate to AndroidX.

它发生是因为 com.android.support:appcompat-v7:29.x.x 不存在

可以查看官方文档revision history

您可以:

  • 使用支持库的最新 28.0.0 版本
  • 迁移到 androidx

Also check this note:

Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components.

You can continue to use the support library. Historical artifacts (those versioned 27 and earlier, and packaged as android.support.*) will remain available on Google Maven. However, all new library development will occur in the AndroidX library.

We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well.

我建议你迁移到 AndroidX

转到重构 > 迁移到 AndroidX > 迁移

com.android.support:appcompat-v7:29.0.1 不存在

替换 implementation 'com.android.support:appcompat-v7:29.0.1' implementation 'androidx.appcompat:appcompat:1.0.2'

// 将现有项目迁移到 AndroidX

//@link::https://developer.android.com/topic/libraries/support-library/packages

随着 Android 9.0(API 级别 28)的发布,有一个名为 AndroidX 的支持库的新版本,它是 Jetpack 的一部分。 AndroidX 库包含现有的支持库,还包括最新的 Jetpack 组件。

AndroidX 所有新项目中的库。您还应该考虑将现有项目也迁移到 AndroidX。

Android工作室

GO TO Refactor >> Refactor this >> migarat to AndroidX

以下table列出了当前从旧支持库包到新androidx包的映射。

@link https://developer.android.com/jetpack/androidx/migrate/class-mappings @linkhttps://developer.android.com/jetpack/androidx/migrate/artifact-mappings

每个版本的 AndroidX 库在开发过程中都经过四个发布渠道。

@link https://developer.android.com/jetpack/androidx/versions/all-channel

将此用于您的 build.gradle (:app)

放在前面:

dependencies {

这个 hack 解决了我的问题:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0'
            }
        }

    }
}