I am having an issue while compiling my JavaFX project for Android. The project includes a bunch of libraries, Undertow Websockets is among them. I downloaded all required jars to my lib directory and included them into dependencies / compile files block of build.gradle file.
I was able to solve other issues with jar-files dependencies (mostly DuplicateFileException), but one Undertow library - undertow-core-1.3.14.Final.jar gives me a little bit of a headache.
When I add it to compile file block of gradle.build file ‘gradlew android’ gives me an error message:
What went wrong: Execution failed for task ‘:createMainDexList’.
Exception in thread “main” com.android.dx.cf.iface.ParseException: severely truncated attribute at com.android.dx.cf.direct.StdAttributeFactory.throwSeverelyTruncated(StdAttributeFactory.java:736) at com.android.dx.cf.direct.StdAttributeFactory.runtimeVisibleParameterAnnotations(StdAttributeFactory.java:661) at com.android.dx.cf.direct.StdAttributeFactory.parse0(StdAttributeFactory.java:162) at com.android.dx.cf.direct.AttributeFactory.parse(AttributeFactory.java:96) at com.android.dx.cf.direct.AttributeListParser.parse(AttributeListParser.java:141) at com.android.dx.cf.direct.AttributeListParser.parseIfNecessary(AttributeListParser.java:115) at com.android.dx.cf.direct.AttributeListParser.getEndOffset(AttributeListParser.java:96) at com.android.dx.cf.direct.MemberListParser.parse(MemberListParser.java:213) at com.android.dx.cf.direct.MemberListParser.parseIfNecessary(MemberListParser.java:108) at com.android.dx.cf.direct.MethodListParser.getList(MethodListParser.java:54) at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:542) at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406) at com.android.dx.cf.direct.DirectClassFile.parseToEndIfNecessary(DirectClassFile.java:397) at com.android.dx.cf.direct.DirectClassFile.getAttributes(DirectClassFile.java:311) at com.android.multidex.MainDexListBuilder.hasRuntimeVisibleAnnotation(MainDexListBuilder.java:191) at com.android.multidex.MainDexListBuilder.keepAnnotated(MainDexListBuilder.java:167) at com.android.multidex.MainDexListBuilder.(MainDexListBuilder.java:121) at com.android.multidex.MainDexListBuilder.main(MainDexListBuilder.java:91) at com.android.multidex.ClassReferenceListBuilder.main(ClassReferenceListBuilder.java:58) …while parsing RuntimeVisibleParameterAnnotations attribute at offset 0009c07 > …while parsing attributes[3] …while parsing methods[1] …while parsing io/undertow/client/http/HttpResponseParser$$generated.class
Below is my build.gradle file contents:
task wrapper(type: Wrapper) {
gradleVersion = '2.10'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.0.7'
}
}
apply plugin: 'org.javafxports.jfxmobile'
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
}
mainClassName = 'com.simlayserstudio.SimlayserStudio'
jfxmobile {
android {
manifest = 'src/android/AndroidManifest.xml'
// compileSdkVersion = 16 // version 4.2.1
compileSdkVersion = 23 // version 6
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/services/io.undertow.attribute.ExchangeAttributeBuilder'
exclude 'META-INF/services/io.undertow.predicate.PredicateBuilder'
exclude 'META-INF/services/io.undertow.server.handlers.builder.HandlerBuilder'
//exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
ios {
infoPList = file('src/ios/Default-Info.plist')
}
}
dependencies {
compile ('commons-codec:commons-codec:1.10',
'commons-io:commons-io:2.4',
'commons-lang:commons-lang:2.6',
// 'io.undertow:undertow-servlet:1.3.14.Final' // Duplicate zip entry [allclasses.jar:javax/annotation/Generated.class
)
compile files(
'/lib/jboss-logging-3.2.1.Final.jar', //ok wtih exclude 'META-INF/INDEX.LIST'
// '/lib/undertow-core-1.3.14.Final.jar', // ERROR com.android.dx.cf.iface.ParseException: severely truncated attribute
'/lib/undertow-servlet-1.3.14.Final.jar', // ok wtih exclude ExchangeAttributeBuilder, PredicateBuilder, HandlerBuilder
'/lib/undertow-websockets-jsr-1.3.14.Final.jar', //ok with exclude 'META-INF/INDEX.LIST'
'/lib/xnio-api-3.3.4.Final.jar', //ok with exclude 'META-INF/INDEX.LIST'
'/lib/xnio-nio-3.3.4.Final.jar', //ok with exclude 'META-INF/INDEX.LIST'
'/lib/apache-commons.jar', //ok
'/lib/com.thoughtworks.xstream.jar', //ok
'/lib/javax.websocket-api-1.0.jar', //ok
'/lib/log4j-1.2.17.jar', //ok
'/lib/xmlpull-xpp3-1.1.4c.jar', //ok
)
}
Did anybody manage generating apk with Undertow Websockets, or encounter similar issues with 3-rd party libraries?
Any help would be much appreciated. Thank you!
I've been able to reproduce the same error you've posted, just by using this dependencies and running ./gradlew android
:
dependencies {
compile ('io.undertow:undertow-servlet:1.3.19.Final') {
exclude group: 'org.jboss.spec.javax.annotation'
}
compile ('io.undertow:undertow-core:1.3.19.Final') {
exclude group: 'org.jboss.spec.javax.annotation'
}
compile ('io.undertow:undertow-websockets-jsr:1.3.19.Final') {
exclude group: 'org.jboss.spec.javax.annotation'
}
}
So in order to find out about the possible issue, I've downloaded the io.undertow` sources from here, added the required dependencies (maybe I'm not using the exact versions):
dependencies {
compile 'org.jboss.logging:jboss-logging-annotations:2.0.1.Final'
compile 'org.jboss.classfilewriter:jboss-classfilewriter:1.0.4.Final'
compile 'org.eclipse.jetty.alpn:alpn-api:1.0.0'
compile 'org.jboss.xnio:xnio-nio:3.3.4.Final'
compile 'org.jboss.xnio:xnio-api:3.3.4.Final'
compile 'org.jboss.logging:jboss-logging:3.2.1.Final'
compile 'org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:1.1.0.Final'
compile 'org.jboss.spec.javax.servlet:jboss-servlet-api_3.1_spec:1.0.0.Final'
}
And to avoid duplicated classes from javax.annotation
, I've downloaded the sources of org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec
from here, and removed these three classes: Generated.java
, PostConstruct.java
and PreDestroy.java
.
I was able to run ./gradlew android
successfully, but I haven't tested it.
In case you still have issues building it or later running it on the device, maybe you can consider other alternatives for websockets like the Tyrus project.
This is a project were we have used it successfully.