Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to use Google architecture components in my app, but after updating android studio to version 3.1.1 when I add android.arch.lifecycle:extensions:1.1.1 dependency into app.gradle file, it will show Failed to resolve: support-fragment
My gradle version is 4.4

enter image description here

This is app 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"
}

Please guid me how to fix it, Thanks

like image 794
hosseinAmini Avatar asked Apr 11 '18 17:04

hosseinAmini


People also ask

How do I add a dependency in gradle?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build. gradle file. This declares a dependency on an Android library module named "mylibrary" (this name must match the library name defined with an include: in your settings.

Where is build gradle file in Android Studio?

The top-level build.gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.


2 Answers

add these two to build.gradle -> repositories

{
mavenCentral()
google() 
}

and add to these are to allprojects

allprojects {
repositories {
mavenCentral()
google()
}
}
like image 91
MehrAmoon Avatar answered Oct 15 '22 09:10

MehrAmoon


i add this line in build.gradle and fixed bug : implementation 'androidx.fragment:fragment:1.2.5'

like image 37
mahsa k Avatar answered Oct 15 '22 08:10

mahsa k