使用 jfxmobile-plugin 为 Android 编译 JavaFX Undertow Websockets 项目时属性被严重截断

Severely truncated attribute while compiling JavaFX Undertow Websockets project for Android with jfxmobile-plugin

我在为 Android 编译 JavaFX 项目时遇到问题。 该项目包括一堆库,Undertow Websockets 就是其中之一。我将所有需要的 jar 下载到我的 lib 目录,并将它们包含到 build.gradle 文件的依赖项/编译文件块中。

我能够解决 jar 文件依赖项的其他问题(主要是 DuplicateFileException),但是一个 Undertow 库 - undertow-core-1.3.14.Final.jar 给了我有点头疼。

当我将它添加到 编译文件 块的 gradle.build 文件‘gradlew android’时,给我一条错误消息:

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

下面是我的 build.gradle 文件内容:

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
    )    


}

有没有人设法用 Undertow Websockets 生成 apk,或者遇到与第 3 方库类似的问题?

如有任何帮助,我们将不胜感激。 谢谢!

我已经能够重现您发布的相同错误,只需使用此依赖项和 运行ning ./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' 
    }
}

所以为了找出可能的问题,我从 here 下载了 io.undertow` 源,添加了所需的依赖项(也许我没有使用确切的版本) :

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'
}

为了避免与 javax.annotation 重复 类,我从 here 下载了 org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec 的源代码,并删除了这三个 类: Generated.javaPostConstruct.javaPreDestroy.java

我能够 运行 ./gradlew android 成功,但我还没有测试过。

如果您仍然无法构建它或稍后 运行将其安装到设备上,也许您可​​以考虑其他 websockets 替代方案,例如 Tyrus 项目。

这是一个 project 我们已经成功使用它。