使用jfxmobile-plugin

时间:2016-03-22 02:39:42

标签: javafx websocket undertow javafxports gluon-mobile

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

我能够解决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.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.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.multidex.ClassReferenceListBuilder.main(ClassReferenceListBuilder.java:58)   ...在偏移量0009c07>处解析RuntimeVisibleParameterAnnotations属性时...解析属性时[3]   ...解析方法时[1]   ...解析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方库相似的问题?

非常感谢任何帮助。 谢谢!

1 个答案:

答案 0 :(得分:0)

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

我能够成功运行PreDestroy.java,但我还没有对其进行测试。

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

这是我们成功使用它的project