AndroidStudio无法直接导入依赖包

在学安卓时用到了RXjava,于是就想导入RXjava的配置环境。平常就是在build.gradle中的dependencies中直接导入,但这几天导不进去了,求帮助,o(╥﹏╥)o

img

plugins {
id 'com.android.application'
}

android {
compileSdk 31

defaultConfig {
    applicationId "com.example.rxjava"
    minSdk 21
    targetSdk 31
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'io.reactivex.rejava2:rxjava:2.0.7'
implementation 'io.reactivex.rejava2:rxandroid:2.0.1'

}

api 替换 implementation 试试。

implementation 'io.reactivex.rejava2:rxjava:2.0.7'
implementation 'io.reactivex.rejava2:rxandroid:2.0.1'

改为

implementation 'io.reactivex.rxjava2:rxandroid:2.0.7'
implementation 'io.reactivex.rxjava2:rxjava:2.0.1'