无法解决:添加 google 体系结构组件依赖项时支持片段错误

Failed to resolve: support-fragment error when add google architecture component dependency

我想在我的应用程序中使用 Google 架构组件,但是在将 android studio 更新到版本 3.1.1 之后,我将 android.arch.lifecycle:extensions:1.1.1 依赖项添加到 app.gradle 文件中, 它将显示 Failed to resolve: support-fragment
我的 gradle 版本是 4.4

这是应用程序gardle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "ir.apptori.myapplication"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
 "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    implementation "android.arch.lifecycle:extensions:1.1.1"
}

请指导我如何修复它,谢谢

我遇到了类似的错误并更改了 repositories 顺序,以便 google()jcenter() 修复它之前出现。

我不得不更改顶层 build.gradle 文件中 buildscript allprojectsrepositories 的顺序.

请查看此提交: https://github.com/kunadawa/ud851-Exercises/commit/9f6720ef4d52c71b206ddaa8477f2cf6e77a66f4

我从 github.

克隆的一个项目刚好发生这种情况

我更新了我的 SDK 和构建工具,并且必须仔细检查所有依赖项以匹配项目中的 buildToolsVersioncompileSdkVersion

当我尝试同步项目时,错误消息不是很清楚,当我尝试 运行 但失败时,它只给了我一个更明确的错误。

Could not find support-fragment.jar (com.android.support:support-fragment:27.0.2).

祝你好运!

我还必须从项目 build.gradle 中删除 Maven url,如:

 buildscript {
        repositories {
            google()
            jcenter()
          //  maven { url 'https://maven.google.com' }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.3'

        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
        }
    }

这对我有用。

对于类似的问题,它通过在 app build.gradle 文件

中将 material 实现从 alpha2 版本更改为 alpha 7 来解决
implementation 'com.google.android.material:material:1.1.0-alpha07'

将这两个添加到 build.gradle -> 存储库

{
mavenCentral()
google() 
}

并将这些添加到所有项目

allprojects {
repositories {
mavenCentral()
google()
}
}

我在 build.gradle 中添加了这一行并修复了错误: implementation 'androidx.fragment:fragment:1.2.5'