JCenter 弃用;对 Gradle 和 Android 的影响

JCenter deprecation; impact on Gradle and Android

我是否应该担心 JCenter 被弃用?

为什么我应该将我的库从 JCenter 迁移到其他 Maven 存储库?

我可以在 Gradle 构建脚本中继续使用 jcenter() 吗?

请参阅

总结:2022 年 2 月 1 日之后 jcenter() 将不再有效。

根据this Gradle blog post

Gradle 7.0 will deprecate the use of jcenter() to resolve dependencies.
You will still be able to use JCenter as a repository, but Gradle will emit a warning.
The jcenter() method will be removed in the next major release.

Gradle has no inherent tie to JCenter or Maven Central, so you can always switch to any other repository of your choice.

并且根据Android Developers

JFrog, the company that maintains the JCenter artifact repository used by many Android projects, recently announced the deprecation and upcoming retirement of JCenter.
According to the announcement, JCenter will allow downloads of existing artifacts until February 1, 2022.

Developers who publish artifacts on JCenter should start migrating packages to a new host, such as Maven Central.

因此,只需确保作者在其他存储库中提供他们的库,然后更新您的构建脚本以允许从这些存储库下载。
例如,在 Gradle 中使用 mavenCentral() 函数启用从 Maven 中央存储库获取依赖项。

实际上,开发人员应该将他们的库移植到 Maven 或 Google。在这种情况下,可以从 Gradle.

中删除 jCenter()

旧库不再维护或开发人员退休时会出现问题。

只有两种可能:

a) 搜索,例如在 Maven 中有一个类似的库。

b) 从 GitHub 下载相应的源代码并从中创建您自己的本地库。

截至 2022-02-01 JCenter 肯定是宕机了。

替换

jcenter()

有了这个:

mavenCentral()

JFrog 网站here提到的最新更新如下:

UPDATE 4/27/2021: We listened to the community and will keep JCenter as a read-only repository indefinitely. Our customers and the community can continue to rely on JCenter as a reliable mirror for Java packages.

jcenter()替换为:

gradlePluginPortal()
mavenCentral()

你必须改变

jcenter()

mavenCentral()

此外,您必须设置一个或多个存储库网址:

repositories {
    mavenCentral()
    maven {
        url = "https://repo1.maven.org/maven2/"
    }
    maven {
        url "https://repo.spring.io/release"
    }
    maven {
        url "https://repository.jboss.org/maven2"
    }
    maven {
        url 'https://repo.jenkins-ci.org/public/'
    }
}

就我而言,我已按照以下步骤完成它:

  1. 将 mavenCentral() 放在 jcenter() 之前
  2. 使用 Android Studio 升级助手升级 gradle(在我的例子中升级到 7.0.3)
  3. 通过插件安装 NDK(并排)(Android Studio)
  4. 清理并重建项目

我尝试了所有方法但没有任何效果,然后手动添加一个新的 maven 存储库,现在它可以工作了。

repositories {
 // ...
 maven { url 'https://repo.gradle.org/gradle/libs-releases/' }
}