ERROR: Failed to resolve: androidx.lifecycle:lifecycle:2.2.0-beta01

Viewed 3884

I'm having issues with the build.gradle file, specially the module 'android.x.lifecycle'.

I have the following error

ERROR: Failed to resolve: androidx.lifecycle:lifecycle:2.2.0-beta01
This is the last version of androidx.lifecycle

I don't know if it a syntax error

This is the build.gradle file

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.flixarts.ar.englishnow"
        minSdkVersion 14
        targetSdkVersion 29
        buildToolsVersion '25.0.2'
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion = '28.0.3'
}

dependencies {
    implementation 'androidx.lifecycle:lifecycle:2.2.0-beta01'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.material:material:1.1.0-beta01'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.gms:play-services-ads:18.2.0'
    implementation 'com.android.support:multidex:1.0.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'
    implementation 'androidx.cardview:cardview:1.0.0'
}
1 Answers

Change this line:

androidx.lifecycle:lifecycle:2.2.0-beta01

with one of these:

implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-beta01"
implementation "androidx.lifecycle:lifecycle-viewmodel:2.2.0-beta01" 
implementation "androidx.lifecycle:lifecycle-livedata:2.2.0-beta01"
implementation "androidx.lifecycle:lifecycle-livedata-core:2.2.0-beta01"
implementation "androidx.lifecycle:lifecycle-runtime:2.2.0-beta01"

More info about Lifecycle here.

Also:

  • change com.android.support:multidex:1.0.3 to androidx.multidex:multidex:2.0.1 since you are using androidx library
  • you are adding implementation 'androidx.appcompat:appcompat:1.1.0' thrice
  • remove the support library: implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  • remove the buildToolsVersion '25.0.2' and buildToolsVersion = '28.0.3'(don't use = in any case). You can specify buildToolsVersion "29.0.2" in the android block or just omit it and gradle will automatically use the latest version according to the targetSdkVersion specified
Related