processing / processing-android

Processing mode and core library to create Android apps with Processing
http://android.processing.org
778 stars 292 forks source link

Multidex – how #317

Open virtualritz opened 7 years ago

virtualritz commented 7 years ago

I'm trying to build a simple (<200lines of code) project with a dependency on HE_MESH (https://github.com/wblut/HE_Mesh). I get a dexing error.

I assume multidex would solve this. How do I activate this in processing-android?

Pre-Dexing /var/folders/rk/8t33jqjj5l12wpq44wwbbnbr0000gp/T/android6356391992191255161sketch/libs/trove-3.1a1.jar -> trove-3.1a1-a24cc89a92cb194993d1f89968eb7168.jar
Converting compiled files and external libraries into /var/folders/rk/8t33jqjj5l12wpq44wwbbnbr0000gp/T/android6356391992191255161sketch/bin/classes.dex...
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
       [dx]     at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:499)
       [dx]     at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:264)
       [dx]     at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:508)
       [dx]     at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
       [dx]     at com.android.dx.merge.DexMerger.merge(DexMerger.java:191)
       [dx]     at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:506)
       [dx]     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:336)
       [dx]     at com.android.dx.command.dexer.Main.runDx(Main.java:291)
       [dx]     at com.android.dx.command.dexer.Main.main(Main.java:247)
       [dx]     at com.android.dx.command.Main.main(Main.java:92)
       [dx] 

BUILD FAILED
/Users/moeller/Documents/Processing/modes/AndroidMode/sdk/tools/ant/build.xml:888: The following error occurred while executing this line:
/Users/moeller/Documents/Processing/modes/AndroidMode/sdk/tools/ant/build.xml:890: The following error occurred while executing this line:
/Users/moeller/Documents/Processing/modes/AndroidMode/sdk/tools/ant/build.xml:902: The following error occurred while executing this line:
/Users/moeller/Documents/Processing/modes/AndroidMode/sdk/tools/ant/build.xml:283: null returned: 2

Total time: 2 minutes 1 second
victordiaz commented 7 years ago

Dex limit in Android its quite painful yet easy problem to solve using Android Studio but I guess it might be a bit more complicated using the Processing toolchain.

If you have access to the .gradle file you should add in the dependencies section compile 'com.android.support:multidex:1.0.0'

and then extend the Application class and add in onCreate MultiDex.install(this);

I guess your scenario might be quite common for any person willing to add a library. It is rare nowadays to not include multidexing in an app with few libraries. Perhaps it should be enabled by default when an external library is loaded?

The downside is that the app takes a little bit more time to start (around 100ms).

codeanticode commented 7 years ago

@virtualritz At this moment we are not planning to add multidexing to the mode (@victordiaz but would be happy to discuss it further, or review PRs :-) ), but the beta versions of the mode allow you to export your sketch as a Gradle project, which then you can import from Android Studio.