Page 1 of 1

Android Docx4J duplicate classes error

PostPosted: Mon Feb 17, 2020 7:07 am
by f80m3
I am trying to follow the GitHub example here: https://github.com/plutext/Docx4j4Android4 to import the Docx4J library into my Android app. However, when I run my Android app, I get the following error (There are many errors, but they all belong to duplicate classes relating to org.apache.commons.lang3.* and org.sl4j.spi.*):

Duplicate class org.apache.commons.lang3.AnnotationUtils found in modules commons-lang3-3.7.jar (commons-lang3-3.7.jar) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
.......
Duplicate class org.slf4j.spi.MarkerFactoryBinder found in modules docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar) and slf4j-android-1.6.1-RC1.jar (slf4j-android-1.6.1-RC1.jar)
......


Below is my app-level build.gradle:
Code: Select all
[code]apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.diffcheckertest"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude("META-INF/*.kotlin_module")
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation files('libs/activation.jar')
    implementation files('libs/additionnal.jar')
    implementation files('libs/awt-bastardised-17v8.jar')
    implementation files('libs/istack-commons-runtime-3.0.4-SNAPSHOT.jar')
    implementation files('libs/jaxb-core-2.3.0-SNAPSHOT-ANDROID.jar')
    implementation files('libs/jaxb-runtime-2.3.0-SNAPSHOT-ANDROID.jar')
    implementation files('libs/slf4j-android-1.6.1-RC1.jar')

    implementation files('libs/commons-lang3-3.7.jar')
    implementation files('libs/commons-text-1.2.jar')

    implementation files('libs/docx4j-6.1.1-SNAPSHOT-shaded.jar')
}[/code]

Below is my project-level gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()
       
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
       
    }
}

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


Below is my project-level build.gradle:
Code: Select all
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()
       
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
       
    }
}

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


I need to use the commons-lang3-3.7jar and the commons-text-1.2.jar's classes in my app.

Re: Android Docx4J duplicate classes error

PostPosted: Mon Feb 17, 2020 7:20 am
by jason
If you want to use those standalone jars, you'll need to remove the org.slf4j and org.apache.commons.lang3 packages from docx4j-6.1.1-SNAPSHOT-shaded.jar.

I need to get around to doing a Android version of docx4j 8.1.x...

Re: Android Docx4J duplicate classes error

PostPosted: Mon Feb 17, 2020 12:20 pm
by f80m3
jason wrote:If you want to use those standalone jars, you'll need to remove the org.slf4j and org.apache.commons.lang3 packages from docx4j-6.1.1-SNAPSHOT-shaded.jar.

I need to get around to doing a Android version of docx4j 8.1.x...


How would I go about removing the org.slf4j and org.apache.commons.lang3 packages from docx4j-6,1,1-SNAPSHOT-shaded.jar?