javafxmobile-plugin icon indicating copy to clipboard operation
javafxmobile-plugin copied to clipboard

Can you use Proguard to solve a problem with "--main-dex-list"

Open JulienSt opened this issue 7 years ago • 4 comments

Hey everybody, I am trying to write a scala App via the javafxmobile-plugin, but I keep running into the all to common problem: com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded

The program runs fine on desktop.

I found several possible solutions to that problem, but none have worked out so far.

The first thing I found is to change the min sdk version to 21, so multidexing is enabled. This does not seem to work for me for some reason, even with the following lines added to the dex options, I still get this problem

        dexOptions {
            additionalParameters += "--min-sdk-version=21"
            additionalParameters += "--multi-dex"
            additionalParameters += "--minimal-main-dex"
            javaMaxHeapSize '3g'
        }

So I kept on searching and found in a stackoverflow-post, that one should disable keepRuntimeAnnotatedClasses. I tried that and indeed the code would compile and even install on my device. Sadly the App just turns the screen black and crashes.

Another common solution (espacially with scala) is to use proguard. In normal Android apps you can use the simple lines

android {
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }
    ...
}

But I haven't found a way to aplly the same plugin inside jfxmobile. Can anybody tell me how I would do that?

I thought about investigating the problem further with the debugger, but nowhere could I find a tutorial on how to enter debug-mode with javafxmobile running on a connected device.

Maybe I am overlooking something trivial or I overcomplicate things, but after 2 weeks of researching this problem online, I simply don't know where I should comtinue my search. So I thought I should ask here. I will appreciate your help!

Further context: I outline my initial goals here: https://stackoverflow.com/questions/51091699/how-does-one-combine-scalafxml-with-gradle

You can look into the code here: https://github.com/JulienSt/javafxmobile-scala-test

If you happen to find a totally different solution to my problem, I would gladly look into it. I already got the following project working: https://github.com/rladstaetter/fx-tictactoe But I only want to use java classes to access FXML if I absolutely have to.

Thank you in advance!

PS: It would be a nice selling point for javafxmobile, if one could create pure scala-apps with macro integration ;)

JulienSt avatar Jul 06 '18 08:07 JulienSt

Just in case you haven't checked it yet, a Gluon sample using Scala: https://github.com/gluonhq/gluon-samples/tree/master/gluon-SQLite-scala

And regarding the debug question, check this: https://stackoverflow.com/questions/44970567/run-debugger-on-javafx-project-in-android/44988910#44988910 https://stackoverflow.com/questions/44538097/export-javafx-project-to-android/44544233#44544233

As for using pro guard, this might help: https://stackoverflow.com/questions/40616077/using-proguard-in-java-modules-android-studio

jperedadnr avatar Jul 22 '18 14:07 jperedadnr

Thank you for the example project! No, I actually haven't seen that until you posted it. The Thing is though, that I am trying to use scalafxml, since it has such a nice feel to it, when using fxml with scala. This example seems to be similar to the project I posted inside the first post. The Main Problem seems to be MacroParadies and the annotations.

I haven't had time to try debugging yet (and pro guard for that matter), since I am tied up in other projects, but I will tell you my results as soon as I get to work on it again. (Hopefully in the next two weeks)

Thank you for the links!

JulienSt avatar Aug 02 '18 21:08 JulienSt

I finally got around to work with pro guard to shrink the program during compile time and my attempt somewhat works. There are some problems though. I outlined the problems with the current method in more detail inside the build.gradle from the project that was attached earlier: https://github.com/JulienSt/javafxmobile-scala-test/blob/master/build.gradle

I might be going about this the wrong way, so it would be nice if somebody can check my methodology. As far as I can see I only need to get rid of these kinds of warnings: Warning: library class javafx.scene.web.WebErrorEvent depends on program class javafx.event.EventType Warning: library class javax.swing.JComponent depends on program class java.beans.VetoableChangeListener

So, if somebody knows how to prefer library-classes over program-classes, please tell me.

I have the complete Log from the app here: https://github.com/JulienSt/javafxmobile-scala-test/blob/master/log.txt

JulienSt avatar Sep 25 '18 14:09 JulienSt

I finally found the answer to the main question: Yes, you can. Simply shrink the jar that is located at def "$buildDir\javafxports\tmp\android\multi-dex\allclasses.jar" and rename the shrunk-jar to allclasses.jar.

The Reason it didn't work for me the first time doesn't lie with proguard, but with javafxmobille. The plugin simply doesn't know what to do with the wrapped javafx-classes. So, sadly scalafxml can't be used with javafxmobille. But one can use normal javafx with scala and javafxmobille. It is way more verbose, but it gets the job done.

PS: I think this issue can be closed.

JulienSt avatar Oct 08 '18 11:10 JulienSt