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



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

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

当我将其添加到gradle.build文件"gradlew-android"的编译文件块时,会给我一条错误消息:

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

线程"main"com.android.dx.cf.iface.ParseException出现异常:处的属性被严重截断com.android.dx.cf.direct.StdAttributeFactory.throwSeverelyTruncated(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(AttributeFactory.java:96)在com.android.dx.cf.direct.AttributeListParser.parse(AttributeListParser.java:141)在com.android.dx.cf.direct.AttributeListParser.parseIfNenecessary(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.parseIfNenecessary(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.parseToEndIfNenecessary(DirectClassFile.java:397)在com.android.dx.cf.direct.DirectClassFile.getAttributes(DirectClassFile.java:311)在com.android.multidex.MainDexListBuilder.hasRuntimeVisibleAnnotation(MainDexListBuilder.java:191)在com.android.multidex.MainDexListBuilder.keepAnnotated(MainDexListBuilder.java:167)在com.android.multidex.MainDexListBuilder.(MainDexListBuilder.java:121)在com.android.multidex.MainDexListBuilder.main(MainDexListBuilder.java:91)在com.android.dotex.ClassReferenceListBuilder.main(ClassReferenceListenBuilder.java:58)…在分析偏移量0009c07>处的RuntimeVisibleParameterAnnotations属性时…在分析属性[3]时…正在分析方法[1]…在解析io/bunderstream/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,或者在第三方库中遇到类似问题?

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

我已经能够重现您发布的相同错误,只需使用此依赖项并运行./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.bunderstream的源代码,添加了所需的依赖项(也许我没有使用确切的版本):

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的源代码,并删除了这三个类:Generated.javaPostConstruct.javaPreDestroy.java

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

如果你在构建它或稍后在设备上运行它时仍然有问题,也许你可以考虑其他websocket的替代方案,比如Tyrus项目。

这是一个我们已经成功使用的项目。

相关内容

  • 没有找到相关文章

最新更新