android - 无法获取 Android 架构组件的资源

标签 android android-studio android-gradle-plugin android-architecture-components

我通过将以下行添加到 build.gradle 来应用到我的项目 Android Architecture Components:

// Android Architecture Lifecycle
compile "android.arch.lifecycle:runtime:1.0.0-alpha1"
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"

// Android Architecture Room
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
compile "android.arch.persistence.room:rxjava2:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"

它成功了,但是在将 Android Studio 更新到 Canary 3 版本后,我在编译时仍然遇到这个错误

Error:org.gradle.api.resources.ResourceException: Could not get resource 'https://jitpack.io/android/arch/lifecycle/runtime/1.0.0-alpha1/runtime-1.0.0-alpha1.pom'.

Error:org.gradle.api.UncheckedIOException: Could not HEAD 'https://jitpack.io/android/arch/lifecycle/runtime/1.0.0-alpha1/runtime-1.0.0-alpha1.pom'. Received status code 401 from server: Unauthorized

...库中的其他 poms 有同样的错误。

我尝试重启 Android Studio,卸载应用程序,当然还有清理重建。

最佳答案

您需要将 Google 正在使用的新公共(public) Maven 存储库添加到您的 build.gradle 文件中。

例如,您可以将它添加到顶级 build.gradle 文件中的 allprojects 闭包中:

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

然后,您的所有模块(例如,app/)都会知道除了在其他地方寻找 Artifact 之外,还要去那里寻找 Artifact 。

从您的错误消息来看,Android Studio 似乎只在 jitpack.io 中查找。

关于android - 无法获取 Android 架构组件的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44348802/

相关文章:

android - Gradle 构建错误 : SAXParseException

android - 通过 gradle 为 Android 中的不同构建类型更改 java 文件的内容

android - android中显示图片的Gridview

android - AsyncTask 和 SQLite 数据库

java - 阅读从 GMail 发送的邮件

android - 查找和替换 Android Studio

java - 方法不会覆盖其父类(super class)中的方法

java - Set<String> 不保存所有数据?

java - 通过标准 SDK 在 Android 8 上显示应用程序图标徽章

java - 使用 flavor 维度时设置 Android applicationId 的正确方法是什么?