代码之家  ›  专栏  ›  技术社区  ›  velena

使用jfxmobile插件为Android编译JavaFX Undertow Websockets项目时严重截断属性

  •  0
  • velena  · 技术社区  · 10 年前

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

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

    当我将其添加到 编译文件 梯度块。构建文件gradlew android给我一条错误消息:

    问题:任务:createMainDexList的执行失败。

    线程主com.android.dx.cf.iface.ParseException中出现异常: 处的严重截断属性 com.android.dx.cf.direct.StdAttributeFactory.throwSeverlyTruncated(StdAttributeFactory.java:736) 在 com.android.dx.cf.direct.StdAttributeFactory.runtimeVisibleParameterAnnotations(StdAttributeFactory.java:661) 在 com.android.dx.cf.direct.StdAttributeFactory.parse0(StdAttributeFactory.java:162) 在 com.android.dx.cf.direct.AttributeFactory.parse(AttributeFacctory.java:96) 在 com.android.dx.cf.direct.AttributeListParser.parse(AttributeListParser.java:141) 在 com.android.dx.cf.direct.AttributeListParser.parseIfNecessary(AttributeListParser.java:115) 在 com.android.dx.cf.direct.AttributeListParser.getEndOffset(AttributeListParser.java:96) 在 com.android.dx.cf.direct.MemberListParser.parse(MemberListParser.java:213) 在 com.android.dx.cf.direct.MemberListParser.parseIfNecessary(MemberListParser.java:108) 在 com.android.dx.cf.direct.MethodListParser.getList(MethodListParser.java:54) 在 com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:542) 在 com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406) 在 com.android.dx.cf.direct.DirectClassFile.parseToEndIfNecessary(DirectClassFile.java:397) 在 com.android.dx.cf.direct.DirectClassFile.getAttributes(DirectClassFile.java:311) 在 com.android.midex.MainDexListBuilder.hasRuntimeVisibleAnnotation(MainDexListBuilder.java:191) 在 com.android.midex.MainDexListBuilder.keepAnnotated(MainDexListBuilder.java:167) 在 com.android.multidex.MainDexListBuilder.(MainDexListBuilder.java:121) 在 com.android.midex.MainDexListBuilder.main(MainDexListBuilder.java:91) 在 com.android.multidex.ClassReferenceListBuilder.main(ClassReference ListBuilder.java:58) 在偏移量0009c07>处解析RuntimeVisibleParameterAnnotations属性时;分析属性[3]时 分析方法[1]时 解析io/undertow/client/http/HttpResponseParser$$generated.class时

    下面是我的身材。渐变文件内容:

    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,或者在第三方库中遇到类似的问题?

    任何帮助都将不胜感激。 非常感谢。

    1 回复  |  直到 10 年前
        1
  •  0
  •   José Pereda    10 年前

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

    因此,为了找出可能的问题,我下载了io。暗流来源 here ,添加了所需的依赖项(可能我没有使用确切的版本):

    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 ,我已经下载了 org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec 从…起 here ,并删除了这三个类: Generated.java , PostConstruct.java PreDestroy.java .

    我能跑了 ./gradlew安卓系统 成功了,但我还没有测试过。

    如果您在构建或稍后在设备上运行它时仍有问题,也许您可以考虑其他Websocket替代方案,例如 Tyrus 项目

    这是一个 project 如果我们成功地使用了它。