无法在Android Studio中重建项目并构建APK

时间:2018-07-17 16:41:01

标签: android android-studio android-gradle build.gradle

这是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.test.app"
        minSdkVersion 19
        targetSdkVersion 27
        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'
        }
        debug {
            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:design:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-    layout:1.1.2'
    implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
    implementation 'co.lujun:androidtagview:1.1.4'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    implementation "com.github.firdausmaulan:GlideSlider:1.3.1"
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
    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'
}

当我要重建项目或构建APK时,发生此错误:

  

程序类型已存在:com.bumptech.glide.GeneratedRequestManagerFactory

我应该怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

在存储库块内的所有项目中添加此行maven { url 'https://jitpack.io' },您将摆脱此问题。发生此问题是因为您错过了编写存储库的操作,并且gradle无法下载该库。

buildscript {


    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        maven { url 'https://jitpack.io' } // add this line, you have missed this line that's why library can't failed to load 
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}