Android app run fails with "duplicate entry: META-INF/services" error

607 views Asked by At

I am trying to convert my app to AndroidX. I have updated it to version 28 (pie) and then converted it to Android X using "refactor-migrate to Android X". Everything appears to be OK, and the project syncs ok in a couple of seconds.

My problem comes when I try to build the file (with build:rebuild project) or run it on an emulator - the run fails with the message

Cause:duplicate entry: META-INF/services/javax.annotation.processing.Processor

I have tried several different "packaging options" entries in the build.gradle file, including:

packagingOptions {
        exclude 'META-INF/*'
    }

and

packagingOptions {
        pickFirst 'META-INF/*'
    }

and

packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

but I get the same message every time. However, if I clean the project (build:Clean Project) then it says the build is OK.

My build.gradle file currently looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "com.barney.aboutmyjourney"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }

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

    packagingOptions {
        exclude 'META-INF/*'
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.gms:play-services-location:17.1.0'
    implementation 'com.github.bumptech.glide:glide:4.2.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

}

I am an Android amateur, and I have to admit that I don't really understand what "META-INF/services" is doing, or where the entry resides. Is my problem a duplicated file, or a duplicated reference in another file?

I don't know what else to try. Can anyone help?

1

There are 1 answers

0
Chris S On

I have made a number of changes, including updating some of the build.gradle dependencies to later versions, and the problem has gone away.

I still don't understand what caused the problem or which specific action solved it, so I would still be grateful if anyone can give any explanation, to help me if it happens again.