简体   繁体   中英

Manifest Merger Failed when importing my aar library into project

Iam new in developing android library.Recently there was a requirement to integrate some part of my app to other client app. For that, I have uploaded an aar format library through sonatype to maven repository.

But the problem arises when i integrate this library to other app.I have encountered some error like-:

Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/android/volley/Response$ErrorListener;

and many more like that.

The problem which I think so far is coming from the multiple dependencies defined in both app and library.

Is there anything which iam doing wrong in my library and how can we remove the duplicate library from the app.

I have tried many options like "multidex enable true and preDexLibraries = false" option but none of that attribute work.

Any help is appreciated.

My library app level gradle is-:

apply plugin: 'com.android.library'
apply from: 'maven-push.gradle'



android {
    compileSdkVersion 26

    useLibrary 'org.apache.http.legacy'

    lintOptions {
        abortOnError false
    }
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        consumerProguardFiles 'proguard-rules.pro'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            useProguard true
            //consumerProguardFiles 'proguard-rules.pro'
            buildConfigField "String", "BASEURL", PROD_SERVICE_URL
            buildConfigField "String", "MERCHANT_ID", MERCHANT_ID
            buildConfigField "String", "ACCESS_CODE", ACCESS_CODE

        }
        debug {
            buildConfigField "String", "BASEURL", STAGING_SERVICE_URL
        }
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:design:26.1.0'
    testImplementation 'junit:junit:4.12'
    implementation 'com.jpardogo.googleprogressbar:library:1.2.0'
    implementation 'com.karumi:dexter:4.2.0'
    implementation 'com.squareup.okhttp:okhttp:2.4.0'
    implementation 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
    implementation 'com.squareup.okhttp:okhttp:2.5.0'
    implementation 'com.squareup.okhttp3:okhttp:3.7.0'
    implementation 'org.jsoup:jsoup:1.7.3'


    implementation 'com.mcxiaoke.volley:library:1.0.17'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.jakewharton:disklrucache:2.0.2'
    //implementation 'com.google.android.gms:play-services-base:15.0.1'
    //compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:multidex:1.0.1'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}
task deleteJar(type: Delete) {
    delete 'libs/jars/logmanagementlib.jar'
}

task createJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('libs/jars/')
    include('classes.jar')
    rename('classes.jar', 'logmanagementlib.jar')
}


createJar.dependsOn(deleteJar, build)

Thanks

In your library AndroidManifest.xml remove everything from Application tag:

<application/>

when you import the library in application, all dependencies you import in the library will be imported in the application so remove the any library you imported in library before in application gradle file

if there is a problem with merging the AndroidManifest.xml you can see the error in the Merged Manifest tab in the bottom left corner

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM