Andrei Tanana
Andrei Tanana

Reputation: 8442

More than one file was found with OS independent path 'AndroidManifest.xml'

I have a multimodule project. After I updated Gradle to 5.4.1 and Android gradle plugin to 3.5.1 version I started getting the following error:

Execution failed for task ':Android.OTT.Framework:mergeDebugJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'AndroidManifest.xml'

Here is the build.gradle of this module:

buildscript {
    rootProject.ext {
        support_version = '28.0.0'
        retrofit_version = '2.6.0'
        kodein_version = '6.2.1'
        butterknife_version = '9.0.0'
        joda_time_version = '2.10.2'
        rxjava_version = '2.2.10'
        rxandroid_version = '2.1.1'
        nanohttpd_version = '2.3.1'
        gson_version = '2.8.5'
        okio_version = '2.2.2'
        annimon_stream_version = '1.2.1'
        leak_canary_version = '1.6.3'
        ok_http_version = '3.12.1'
        lifecycle_version = '1.1.1'

        mockito_version = '2.28.2'
        mockito_kotlin_version = '2.1.0'
        kluent_version = '1.41'
    }

    repositories {
        google()
        maven { url 'https://maven.fabric.io/public' }
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven { url 'https://plugins.gradle.org/m2/' }
    }

    dependencies {
        // These docs use an open ended version so that our plugin
        // can be updated quickly in response to Android tooling updates

        // We recommend changing it to the latest version from our changelog:
        // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
        classpath 'io.fabric.tools:gradle:1.+'

        classpath "com.jakewharton:butterknife-gradle-plugin:$butterknife_version"
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'
apply plugin: 'com.jakewharton.butterknife'

androidExtensions {
    experimental = true
}

repositories {
    google()
    maven { url 'https://maven.fabric.io/public' }
    mavenCentral()
    jcenter()
    maven { url "https://jitpack.io" }
    maven { url "https://dl.bintray.com/deltatre/exoplayer" }
}

allprojects {
    repositories {
        google()
        flatDir {
            dirs './divaLibs'
        }
        maven {
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
}

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            consumerProguardFiles 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
    dataBinding {
        enabled = true
    }
}

realm {
    syncEnabled = true
}

dependencies {
    api project(':Android.OTT.OfflineVideo')
    api project(':Android.OTT.D3Foundation')

    // START DIVA PLAYER
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'divaLibs')
    api files('divaLibs/divaandroidlib-release-4.7.2.aar')
    implementation 'com.deltatre.android.exoplayer:exoplayer:2.9.5.1'
    implementation 'com.github.davibe:MD360Player4Android:dev-SNAPSHOT'
    implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.10.2'

    api "com.google.code.gson:gson:$gson_version"
    api "joda-time:joda-time:$joda_time_version" // needed also by Diva
    implementation 'com.google.android.gms:play-services-base:16.1.0'
    implementation 'com.google.android.gms:play-services-ads:17.2.1'
    implementation 'com.google.android.gms:play-services-analytics:16.0.8'
    implementation 'com.google.android.gms:play-services-cast:16.2.0'
    implementation 'com.google.android.gms:play-services-cast-framework:16.2.0'
    implementation files('divaLibs/comscore-3.1502.26.jar')
    implementation 'com.google.vr:sdk-videowidget:1.180.0'

    //Firebase
    api 'com.google.firebase:firebase-messaging:18.0.0'
    api 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.android.gms:play-services-tagmanager:16.0.8'
    // Urban Airship - FCM
    api 'com.urbanairship.android:urbanairship-fcm:10.0.2'
    // Support
    api "com.android.support:design:$support_version"
    api "com.android.support:cardview-v7:$support_version"
    api "com.android.support:recyclerview-v7:$support_version"
    api "com.android.support:support-v4:$support_version"
    api "com.android.support:mediarouter-v7:$support_version"
    api "com.android.support:appcompat-v7:$support_version"
    api "com.android.support:support-v13:$support_version"
    api "com.android.support:customtabs:$support_version"
    api 'com.android.support.constraint:constraint-layout:1.1.3'
    api 'com.android.support:multidex:1.0.3'

    implementation "android.arch.lifecycle:viewmodel:$lifecycle_version"
    implementation "android.arch.lifecycle:extensions:$lifecycle_version"

    // Analytics
    api('com.crashlytics.sdk.android:answers:1.4.7@aar') {
        transitive = true
    }
    api('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') {
        transitive = true
    }
    // Ui
    api 'me.relex:circleindicator:1.2.2@aar'
    api 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'com.afollestad.material-dialogs:core:0.9.5.0'
    // RETROFIT
    api "com.squareup.retrofit2:retrofit:$retrofit_version"
    api "com.squareup.retrofit2:converter-gson:$retrofit_version"
    api "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
    // ok http
    implementation "com.squareup.okhttp3:okhttp:$ok_http_version"
    implementation "com.squareup.okhttp3:logging-interceptor:$ok_http_version"
    // Rx
    api "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
    api "io.reactivex.rxjava2:rxjava:$rxjava_version"
    api 'com.jakewharton.rxbinding2:rxbinding:2.2.0'
    // IoC
    api "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
    api "org.kodein.di:kodein-di-framework-android-support:$kodein_version"
    // Usefull
    api "com.annimon:stream:$annimon_stream_version"
    api "com.jakewharton:butterknife:$butterknife_version"
    kapt "com.jakewharton:butterknife-compiler:$butterknife_version"
    api 'com.jakewharton.timber:timber:4.7.1'
    implementation "com.squareup.okio:okio:$okio_version"
    implementation "org.nanohttpd:nanohttpd:$nanohttpd_version"
    implementation 'online.devliving:securedpreferencestore:0.7.4'
    api 'com.jakewharton:process-phoenix:2.0.0'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    // TV
    api "com.android.support:leanback-v17:$support_version"

    // Leak Canary
    debugImplementation "com.squareup.leakcanary:leakcanary-android:$leak_canary_version"
    releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary_version"
    debugImplementation "com.squareup.leakcanary:leakcanary-support-fragment:$leak_canary_version"

    testImplementation 'junit:junit:4.12'
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockito_kotlin_version"
    testImplementation "org.mockito:mockito-inline:$mockito_version"
    testImplementation "org.amshove.kluent:kluent-android:$kluent_version"

    // Exomedia
    implementation 'com.devbrackets.android:exomedia:4.3.0'

    androidTestImplementation "org.mockito:mockito-android:$mockito_version"
}

Here is the build.gradle of the project:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        maven { url 'https://maven.fabric.io/public' }
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven { url 'https://plugins.gradle.org/m2/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath 'io.fabric.tools:gradle:1.+'
        classpath 'io.realm:realm-gradle-plugin:5.11.0'
        classpath 'com.google.gms:google-services:4.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
}

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

build.gradle of the Android.OTT.OfflineVideo module:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

buildscript {
    rootProject.ext {
        jsoup_version = '1.12.1'
    }
}


android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            consumerProguardFiles 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

realm {
    syncEnabled = true
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
    implementation "com.annimon:stream:$annimon_stream_version"
    implementation "com.google.code.gson:gson:$gson_version"
    implementation "org.nanohttpd:nanohttpd:$nanohttpd_version"
    implementation "org.jsoup:jsoup:$jsoup_version"
    implementation "joda-time:joda-time:$joda_time_version"
    implementation "com.android.support:support-annotations:$support_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

build.gradle of the Android.OTT.D3Foundation module:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            consumerProguardFiles 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation "com.android.support:support-annotations:28.0.0"//todo
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.amshove.kluent:kluent-android:1.41'
    testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0'
    testImplementation "org.mockito:mockito-inline:2.23.4"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
    mavenCentral()
}

I saw a lot of questions like this one. But this is not my case I guess because I cannot just ignore AndroidManifest.xml files. Thanks in advance!

Upvotes: 3

Views: 7526

Answers (4)

AMOL PATIL
AMOL PATIL

Reputation: 97

I tried a lot of solutions and end up with the solution -

If your are using a gradle plugin -

classpath 'com.android.tools.build:gradle:3.5.x'

you may face the same issue.

Then i tried to degrade the gradle plugin as -

classpath 'com.android.tools.build:gradle:3.4.x'

OR I recommend to use -

classpath 'com.android.tools.build:gradle:3.4.2'

which is a most stable version of gradle plugin.

Then File -> invalidate cache/restart. Clean your project and rebuild it. It will work now!

Upvotes: 2

Josip
Josip

Reputation: 66

I received the same error after finally updating to AndroidX. I was alluded by some other answers to revert back some libraries to their last known working versions. Most importantly, the android gradle plugin. I have the same version as you:

classpath 'com.android.tools.build:gradle:3.5.1'

I reverted it back to my last known stable version, which for me was 3.4.0.

After syncing the project, then clean rebuilding it, the compiler actually provided a meaningful error message pointing me to something completely unrelated to any of my AndroidManifest.xml files. In other words, I got the actual issue either described or linked to a file. From there on, it was as easy as identifying the problem (usually underlined in red) and fixing it.

Therefore, I suggest you figure out the issue with an older android gradle plugin version, like

classpath 'com.android.tools.build:gradle:3.4.0'

then revert back (or keep the old one) after finally finding and fixing the issue.

Upvotes: 4

Muhammad Shujja
Muhammad Shujja

Reputation: 133

Clean project and then invalidate cache and restart the studio or if it doesn't work then, Down grade your gradle version then sync and after sync completed, change it back to the latest version and sync again. Hope it will solve your problem

Upvotes: 0

Pavlo Ostasha
Pavlo Ostasha

Reputation: 16729

Based on where an error took place - in the mergeDebugJavaResource gradle task and on error message about multiple Android Manifests I can assume that the problem is that there are several manifests(for example one for debug and one for production) and there are no proper manifest merging rules.

I've encountered similar issue several times and each time it was due to the absence of proper merge rules markers. Usually I needed to remove or replace some values in my main manifest like this

<activity android:name="com.example.ActivityOne"
    android:screenOrientation="portrait"
    tools:remove="android:windowSoftInputMode">

<activity android:name="com.example.ActivityOne"
    android:theme="@newtheme"
    android:exported="true"
    android:screenOrientation="portrait"
    tools:replace="android:theme,android:exported">

it always worked.

Afterwards you can inspect merged manifest to find inconsistencies and errors and adjust your merge rule markers.

More details in the documentation

While it is not an exact answer to your question I hope it will help.

Upvotes: 1

Related Questions