在 android 工作室中添加库?

Add library in android studio?

当我想添加这个库时:

implementation 'com.github.bumptech.glide:glide:4.9.0'

我的android出现这个错误:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.github.bumptech.glide:glide:4.9.0.

这是我的应用程序模块

apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.example.mahdi.chatapp"
    minSdkVersion 16
    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(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.google.firebase:firebase-config:16.3.0'
    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 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.google.firebase:firebase-database:16.0.6'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.rengwuxian.materialedittext:library:2.1.4'
    implementation 'de.hdodenhof:circleimageview:3.0.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
}

apply plugin: 'com.google.gms.google-services'

您是否在 Gradle 文件中添加了此代码

repositories {
  mavenCentral()
  google()
}

使用最新版本的 glide,即版本 4 以上, 你必须添加一个额外的依赖项(滑行编译器)

dependencies {
 implementation 'com.github.bumptech.glide:glide:4.9.0'
 annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}

并且在存储库中你必须添加

repositories {
  mavenCentral()
  google()
}

参考:https://github.com/bumptech/glide

您还没有添加annotationProcessor

repositories {
mavenCentral()
maven { url 'https://maven.google.com' }
}

dependencies {
compile 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}

这是Glide文档中给出的下载glide的代码。看到这个link:http://bumptech.github.io/glide/doc/download-setup.html#gradle