错误:无法解析:androidx.lifecycle:lifecycle:2.2.0-beta01

Mau*_*ato 5 android android-lifecycle build.gradle androidx

我的文件有问题build.gradle,特别是 module 'android.x.lifecycle'。

我有以下错误

ERROR: Failed to resolve: androidx.lifecycle:lifecycle:2.2.0-beta01
This is the last version of androidx.lifecycle
Run Code Online (Sandbox Code Playgroud)

不知道是不是语法错误

这是build.gradle文件

    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'
}
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 4

更改这一行:

androidx.lifecycle:lifecycle:2.2.0-beta01
Run Code Online (Sandbox Code Playgroud)

其中之一:

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"
Run Code Online (Sandbox Code Playgroud)

有关生命周期的更多信息请参见此处。

还:

  • 更改com.android.support:multidex:1.0.3为,androidx.multidex:multidex:2.0.1因为您正在使用 androidx 库
  • 你要添加implementation 'androidx.appcompat:appcompat:1.1.0'三次
  • 删除支持库:implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  • 删除buildToolsVersion '25.0.2'and buildToolsVersion = '28.0.3'(在任何情况下都不要使用=)。buildToolsVersion "29.0.2"你可以在block 中指定android或者直接省略,gradle 会根据targetSdkVersion指定自动使用最新版本