Android Studio compilation error

2,390 views
Skip to first unread message

Tom Wilson

unread,
Dec 28, 2015, 6:06:10 PM12/28/15
to HAPI FHIR
I'm trying the new hapi-fhir-android module 1.3 and am getting a number of duplicate entry errors on compilation. I've been excluding modules as the errors pop up, which worked until I got to this:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: ca/uhn/fhir/context/BaseRuntimeChildDatatypeDefinition.class


This is the gradle file I have right now:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'commons-codec:commons-codec:1.10'
compile ('ca.uhn.hapi.fhir:hapi-fhir-android:1.2:dstu2'){
exclude group: 'javax.servlet'
exclude group: 'org.apache.httpcomponents'
exclude group: 'org.codehaus.woodstox'
exclude group: 'org.glassfish'
}
}

So why would it complain about a duplicate HAPI library? Or am I missing something?

Tom Wilson

unread,
Dec 29, 2015, 11:24:15 AM12/29/15
to HAPI FHIR
More investigation was warranted, so I took a tutorial project


Confirmed it compiles and runs, then added the HAPI dependency to gradle, here's the full dependencies list:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-android', version: '1.3', classifier: 'dstu2'
}

Now I get the following output when attempting to run it. 


Warning:Dependency org.apache.httpcomponents:httpclient:4.4 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
Warning:Dependency org.apache.httpcomponents:httpclient:4.4 is ignored for release as it may be conflicting with the internal version provided by Android.

and here's the gradle output:

Information:Gradle tasks [:app:assembleDebug]
Warning:Dependency org.apache.httpcomponents:httpclient:4.4 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
Warning:Dependency org.apache.httpcomponents:httpclient:4.4 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72220Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2220Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42220Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava
Note: C:\Users\asdf\AndroidStudioProjects\materiallogindemo\app\src\main\java\com\sourcey\materiallogindemo\MainActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:preDexDebug
trouble processing "javax/xml/stream/EventFilter.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
1 error; aborting
Error:Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_71\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 13.472 secs
Information:1 error
Information:2 warnings
Information:See complete output in console

If I add multiDexEnabled true, then I get a more specific conflict error:

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: org/apache/http/MessageConstraintException.class

So that's what I've learned so far.

Tom Wilson

unread,
Dec 29, 2015, 11:26:24 AM12/29/15
to HAPI FHIR
Here's the full gradle file, with library exclusions

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion '22.0.1'

defaultConfig {
applicationId "com.sourcey.materialloginexample"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'com.jakewharton:butterknife:7.0.1'
    compile(group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-android', version: '1.3', classifier: 'dstu2') {
} 

Tom Wilson

unread,
Dec 29, 2015, 7:14:18 PM12/29/15
to HAPI FHIR
Got things working by simply extracting the jar files and putting them directly in the lib folder. But still, the simple gradle import should work, right?

Thomas Andersen

unread,
Dec 30, 2015, 11:48:23 AM12/30/15
to HAPI FHIR
I've had most succes using this import on hapi fhir

compile 'ca.uhn.hapi.fhir:hapi-fhir-android:1.3:dstu2@jar'

Doing so only import the hapi fhir android dstu2 jar and not all dependencies specified in the pom file.

I've created a small sample project on github showing how to get it working with a simple list of all patients.

Reply all
Reply to author
Forward
0 new messages