jfxmobile-plugin apk generation fails for double visit of a single jar

213 views Asked by At

My javafxport android project (gradle project) fails due to some weird duplicate file exception. The reason for this exception occurs is clear to me: Every library my project depends on (either my own developed libraries or 3rd party libraries like jfoenix.jar) is visited twice by the jfxmobile-plugin since the exception indicates that a file, say X, is found in two different jar files which in fact are the same single artifact.

Here is a more detailed description:

jfxmobile-plugin version : org.javafxports:jfxmobile-plugin:1.1.0

Sample dependency from build.gradle:

dependencies {
    androidCompile 'com.jfoenix:jfoenix:1.0.0'
}

Creating api using this command:

gradle androidInstall

results in:

FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':mylib-android-demo-dist:apkDebug'.
> com.android.builder.packaging.DuplicateFileException:
Duplicate files copied in APK resources/font/roboto/Apache License.txt
File 1: C:\Users\Amin\.m2\repository\com\jfoenix\jfoenix\1.0.0\jfoenix-1.0.0.jar
File 2: C:\Users\Amin\.m2\repository\com\jfoenix\jfoenix\1.0.0\jfoenix-1.0.0.jar

Can anyone guess what's happening here?

Here is real build.gradle file:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.1.0'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

mainClassName = 'com.mycompany.MainClass'

dependencies {
    compile ('com.mycompany:mylib-android-demo-predist:1.1-SNAPSHOT')
    {
        exclude module: 'stax-api'
    }
    androidCompile 'com.github.tony19:logback-android-core:1.1.1-5'
    androidCompile('com.github.tony19:logback-android-classic:1.1.1-5') {
        exclude group: 'com.google.android', module: 'android'
    }
    androidCompile 'com.jfoenix:jfoenix:1.0.0'
}

jfxmobile {
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
}

Note that I've integrated all the other dependencies into a single jar file using maven dependency plugin.

Very important: The same issue is with jfxrt.jar file; there is a file 'META-INF/INDEX.LIST' which is printed out as a duplicate file by the grandle androidInstall task. This jfxrt.jar file is not a declared dependency by any of my own libraries but is a javafx runtime for android which comes from javafxports project by the gradle plugin (jfxmobile-plugin) itself.

1

There are 1 answers

0
dzim On

The Problem you are facing is a very common one with Gradle / Android. The Problem is, that a (license) file with the same name was already copied to the target location from another JAR file. To solve this, please refer to the Gradle packagingOptions either on JavaFXPorts' documentation under the Android section or have a look at the Gradle documentation on GitHub. (I'd prefer not to exclude the licences altogether, but pick the first one encountered ( pickFirst ).

I'm currently developing an JavaFXPorts application as well and needed to do this, too...