简体   繁体   中英

Library dependency not working with module

I'm using Android Studio. I have two modules: the app (UI) and a library. When tested separately, both compile and work as they should, but when I try to use some of the library classes on the app, I can't build the project. I get this error:

失败的Android Studio屏幕截图

Error: Program type already present: org.apache.xmlbeans.xml.stream.Location

My library build.gradle has just a few lines:

apply plugin: 'java-library'


dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'org.apache.poi:poi:3.17'
implementation 'org.apache.poi:poi-ooxml:3.17'

}

sourceCompatibility = "7"
targetCompatibility = "7"

Then my app's build.gradle is this

android {
compileSdkVersion 28
defaultConfig {
    applicationId "skrb.appprueba"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
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'
implementation 'com.android.support:design:28.0.0'
implementation project(path: ':coreLib')

}

When adding this ( implementation project(path: ':coreLib') , I get the error and I don't know how to solve it.

Things that I tried:

  • Cleaning and rebuilding the project.
  • Setting multiDexEnabled to true

Try this one:

implementation(project(path: ':coreLib')) {
    exclude module: 'poi'
    exclude module: 'poi-ooxml'
}

Here you could find more information why this error happen.

according to the error message, it should rather be:

implementation (project(path: ":coreLib")) {
    exclude group: "org.apache.xmlbeans"
}

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