1

I am trying to build a simple android project in which I want to use some hapi-fhir dependencies. However, despite the built is successful, when I am running the application I get a duplicate classes error. The dependencies I am trying to add are the following:

implementation 'ca.uhn.hapi.fhir:hapi-fhir-base:4.1.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu2:4.1.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-r4:4.1.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-validation-resources-r4:4.1.0'
implementation group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-validation', version: '4.1.0'

After commenting out each one I conclude that the issue is deriving from the last one (hapi-fhir-validation).

I have also added this dependency to prevent some previous issue.

implementation 'androidx.multidex:multidex:2.0.1'

While running the failed tasks are the following:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class org.apache.commons.logging.Log found in modules jetified-commons-logging-1.2 (commons-logging:commons-logging:1.2) and jetified-jcl-over-slf4j-1.7.28 (org.slf4j:jcl-over-slf4j:1.7.28)
     Duplicate class org.apache.commons.logging.LogConfigurationException found in modules jetified-commons-logging-1.2 (commons-logging:commons-logging:1.2) and jetified-jcl-over-slf4j-1.7.28 (org.slf4j:jcl-over-slf4j:1.7.28)
     Duplicate class org.apache.commons.logging.LogFactory found in modules jetified-commons-logging-1.2 (commons-logging:commons-logging:1.2) and jetified-jcl-over-slf4j-1.7.28 (org.slf4j:jcl-over-slf4j:1.7.28)
     Duplicate class org.apache.commons.logging.impl.NoOpLog found in modules jetified-commons-logging-1.2 (commons-logging:commons-logging:1.2) and jetified-jcl-over-slf4j-1.7.28 (org.slf4j:jcl-over-slf4j:1.7.28)
     Duplicate class org.apache.commons.logging.impl.SimpleLog found in modules jetified-commons-logging-1.2 (commons-logging:commons-logging:1.2) and jetified-jcl-over-slf4j-1.7.28 (org.slf4j:jcl-over-slf4j:1.7.28)
     Duplicate class org.apache.commons.logging.impl.SimpleLog$1 found in modules jetified-commons-logging-1.2 (commons-logging:commons-logging:1.2) and jetified-jcl-over-slf4j-1.7.28 (org.slf4j:jcl-over-slf4j:1.7.28)
     
     Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeDebugJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'META-INF/DEPENDENCIES'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 8s

Any advice on how to proceed will be very useful. Please let me know if you need any more information.

Thank you in advance!!

konkouts
  • 51
  • 1
  • 6

1 Answers1

0

Currently made this work by importing the dependency while excluding the one that appeared as duplicate as follows:

implementation('ca.uhn.hapi.fhir:hapi-fhir-validation:4.1.0'){
    exclude group: 'commons-logging', module: 'commons-logging'
}

instead of :

 implementation 'ca.uhn.hapi.fhir:hapi-fhir-validation:4.1.0'
konkouts
  • 51
  • 1
  • 6