1

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 screenshot of failed build

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
TylerH
  • 20,799
  • 66
  • 75
  • 101
Guido Chia
  • 15
  • 7
  • Looks like a naming or version conflict of the dependency `org.apache.xmlbeans.xml.stream.Location`. Have look at [this answer](https://stackoverflow.com/a/49767860/3559908) – Vall0n Jan 03 '19 at 15:22

2 Answers2

0

Try this one:

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

Here you could find more information why this error happen.

Dmytro Ivanov
  • 1,260
  • 1
  • 8
  • 10
0

according to the error message, it should rather be:

implementation (project(path: ":coreLib")) {
    exclude group: "org.apache.xmlbeans"
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Now getting java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Color; – Guido Chia Jan 03 '19 at 15:45
  • @GuidoChia `xmlbeans` by itself has no dependencies (despite it should be already included in the package once); see for yourself: https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans/3.0.2 but you are actually using Java libraries in an Android project, which uses a subset of Java, which lacks some of the Java SE classes. therefore, you have to add the one absent class: https://github.com/centic9/poi-on-android/blob/master/poishadow/src/main/java/org/apache/poi/java/awt/Color.java (make sure the package name matches the expected one). – Martin Zeitler Jan 03 '19 at 17:02