Android Tutorial MultiDex - Solves the too many methods error

Erel

Administrator
Staff member
Licensed User
B4A v6.8 adds support for MultiDex compilation.

Enabling MultiDex:
B4X:
'main module
#MultiDex: True
With MultiDex enabled, the compiled classes are split into multiple dex files as needed.

When to do use it?

Only if you encounter one of the following errors during compilation:
- Too many field references
- Too many method references


There are issues with MultiDex and Android 2.x devices, however these devices are now less relevant: https://developer.android.com/about/dashboards/index.html

B4A v6.80

Developers who use this version should replace the existing Dexer.jar with this one: www.b4x.com/android/files/Dexer.jar

Close the IDE and copy the updated Dexer.jar to the installation folder. It fixes an issue with Android 4 and the MultiDex feature.

Tips

- Don't use this feature if not needed. Compilation will be a bit slower and there are no benefits.
- Test your APK on an Android 4.x device. There is no native support for MultiDex on Android 4.x so the process is more fragile.
 
Last edited:

mrred128

Active Member
Licensed User
There are probably more 2.x devices out there than google would know. They have been prevented from actively participating in the store and cloud infrastructure for quite some time now.

Even the 4.04 devices I have (2) are supposed to be about the same percentage in their charts. I have a few clients that still use that vintage.
 

Syd Wright

Active Member
Licensed User
I have been struggeling with the "Too many constants" problem for ages now.
Very good to read that with the "Multidex" compilation this error might become a thing of the past.

Just to add that in my case I have an app with more than 37000 lines of code.
My conclusion is that the problem has to do with the length of my code. For example I can get around the "Too many constants" error by:

1. Moving some code to classes or libraries (althought that often creates extra complications)
2. Reducing the number of subs and in stead inserting short blocks of code directly where they are needed.
3. Simply reducing the amount of text. A good example is that when the "Too many constants" error started to appear again (while debugging), I then changed things like:

B4X:
Dim n As Long
Dim m As Long
Dim p As Long
Dim q As Long
Dim t As Long
into:
B4X:
Dim n, m, p, q, t As Long
This reduces the number of code lines and number of characters, and solves the error while debugging!
 
Last edited:
Top