简体   繁体   English

将aar库导入项目时,清单合并失败

[英]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. Iam是开发android库的新手。最近需要将我的应用程序的某些部分集成到其他客户端应用程序。 For that, I have uploaded an aar format library through sonatype to maven repository. 为此,我已经通过sonatype将aar格式的库上传到了Maven仓库。

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; 错误:将字节码转换为dex时出错:原因:com.android.dex.DexException:多个dex文件定义了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. 我尝试了许多选项,例如“ multidex enable true和preDexLibraries = false”选项,但该属性均无效。

Any help is appreciated. 任何帮助表示赞赏。

My library app level gradle is-: 我的图书馆应用级别的gradle是:

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: 在您的库AndroidManifest.xml中,从Application标签中删除所有内容:

<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 当您在应用程序中导入库时,您在库中导入的所有dependencies都将导入到应用程序中,因此请删除应用程序gradle文件中之前在库中导入的所有库。

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 如果合并AndroidManifest.xml存在问题,则可以在左下角的“ Merged Manifest选项卡中看到错误

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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