0

I'm having this exact problem, when trying to use Jersey (Client) in a Gluon app: https://bitbucket.org/javafxports/android/issues/68/proguard-complains-about-duplicate-classes

The issue is marked as resolved. Does that mean it should work (without a workaround)? My app does work on iPad (albeit with a lot of warnings), the issue occurs only when trying to run on Android.

Steven Van Impe
  • 1,153
  • 8
  • 15

1 Answers1

0

For now, the android tasks will fail if you try to add the same class twice to the dex file.

If you happen to add some dependency that adds any class already in the rt.jar, that will fail.

Typically, when adding Jersey dependencies, javax.annotation classes are added from javax.annotation-api-1.2.jar, while some of them are already present in the JDK.

The solution, in case you don't have the source code to remove those duplicated classes, will be excluding some groups from the dependencies.

This works for me, at least running android task, but without further testing with a real case:

dependencies {
    compile 'com.gluonhq:charm:2.2.0'
    compile ('org.glassfish.jersey.core:jersey-client:2.22.2') {
        exclude group: 'javax.annotation'
        exclude group: 'javax.inject'
    }

    androidRuntime 'com.gluonhq:charm-android:2.2.0'
    iosRuntime 'com.gluonhq:charm-ios:2.0.0'
    desktopRuntime 'com.gluonhq:charm-desktop:2.0.0'
}
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • That got me a bit further, but I now get the following error: Unable to install /Users/Steven/Library/Mobile Documents/com~apple~CloudDocs/HoGent/Projecten II/JavaFX Client (Gluon)/build/javafxports/android/JavaFX Client (Gluon).apk com.android.ddmlib.InstallException: Unable to upload some APKs at com.android.ddmlib.Device.installPackages(Device.java:913) at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:105) at com.android.builder.testing.ConnectedDevice$installPackages$1.call(Unknown Source) ... – Steven Van Impe May 03 '16 at 09:52
  • Maybe this new error is not related to the previous one, but you didn't see it because the task failed sooner. If that's the case please create another question. If it is related, edit your question and post the stacktrace so we can see what's happening. – José Pereda May 03 '16 at 09:57
  • I assume it's related because I've never had this exception with other apps. The full stacktrace is here: http://pastebin.com/JFxqbKrf – Steven Van Impe May 03 '16 at 10:02
  • Can you run `android` task? Does it creates the apk? If so, try to install it manually (with `adb` or downloading it via dropbox...) – José Pereda May 03 '16 at 10:17
  • I was able to create an apk with the `android` task, but the application crashes on startup due to missing classes (in this case `javax.annotation.Priority`. I am guessing the `exclude group` lines exclude more than just the duplicate classes? – Steven Van Impe May 03 '16 at 17:05
  • The problem then has to be solved by downloading and adding the source code of `javafx.annotation` to the project (from [here](https://java.net/projects/glassfish/sources/svn/show/tags/javax.annotation-api-1.2)), removing the duplicated classes (`Generated`, `PostConstruct` and `PreDeploy`). – José Pereda May 03 '16 at 19:12
  • Thanks Jose, this worked for me. `androidInstall` still doesn't work and I get a lot of exceptions related to missing classes (on iPad as well), but the app does work now. – Steven Van Impe May 04 '16 at 12:02
  • Track what classes are missing and see if you can add them to the project as well – José Pereda May 04 '16 at 12:04