Android Question Cannot compile anymore, dex problem.

Nb1320

Member
Licensed User
Longtime User
B4X:
B4A version: 5.02 (1)
Parsing code.    (0.35s)
Compiling code.    (0.60s)
Compiling layouts code.    (0.15s)
Generating R file.    (0.08s)
Compiling generated Java code.    (9.17s)
Convert byte code - optimized dex.    Error
trouble writing output: Too many field references: 66775; max is 65536.
You may try using --multi-dex option.
References by package:
     5 android.app
     7 android.content.pm
    19 android.graphics
     1 android.hardware
     6 android.os
     7 android.provider
     4 android.util
     3 android.view
   119 anywheresoftware.b4a
    25 anywheresoftware.b4a.agraham.reflection
    81 anywheresoftware.b4a.keywords
   125 anywheresoftware.b4a.keywords.constants
   188 anywheresoftware.b4a.objects
    13 anywheresoftware.b4a.objects.collections
    15 anywheresoftware.b4a.objects.drawable
     3 anywheresoftware.b4a.objects.streams
   172 anywheresoftware.b4a.phone
    70 anywheresoftware.b4a.randomaccessfile
   105 aurelienribon.tweenengine
    56 aurelienribon.tweenengine.equations
     2 aurelienribon.tweenengine.primitives
65630 b4a.example
   101 com.rootsoft.tweenengine
     9 java.lang
     4 java.lang.annotation
     2 java.nio
     1 java.util
     2 java.util.concurrent


This is what I am getting now when I try to compile my app, I have been working on it for a while so it is pretty big, but I have never seen this until today. I have looked into the multi-dex that it mentions, but I can't find anything that pertains to B4A and the issue. I REALLY hope this is an easy, quick fix. I appreciate any help! Thanks! :)
 

Nb1320

Member
Licensed User
Longtime User
Sorry, I should have mentioned that. That was the only thing I could find somewhat concerning the issue, I did increase it, but no change. Thanks though.
 
Upvote 0

Nb1320

Member
Licensed User
Longtime User
B4X:
Convert byte code - optimized dex.    Error
trouble writing output: Too many field references: 66775; max is 65536.

thedesolatesoul, what can I do to make the number decrease. I can't understand what it is that controls this number. Lines of code, files, modules, there may be a way I can decrease whatever it is so that I can start working on it again. Thanks.
 
Upvote 0

Nb1320

Member
Licensed User
Longtime User
I read over that page before trying to figure something out, i'll look again and maybe come across something. Thanks for the help.
 
Upvote 0

Nb1320

Member
Licensed User
Longtime User
Still having a problem with this, I just bought a new license to use the new version and now I can't find a way around this issue. I have tried everything I could think of, but nothing works. I will try to breakdown my problem.

I am building an app that has A LOT of activity modules that each open there own designer made file. I have it setup like this because of the way that I understand statemanager to work. Is there a way to make one activity module work with multiple designer made files.

Please excuse my bad pseudo code, not sure if its all correct or not, but that isn't my actual coding.


If I could make this : "Activity,"LIST""

Sub Activity_Pause(UserClosed As Boolean)

StateManager.SaveState(Activity,"LIST")

End Sub

a designer file instead of the activity module, I think it would work, is this possible?

Thank you for the help!



B4X:
Sub Globals

    Dim MyMenu As AnimatedSlidingMenu
   
End Sub


Sub Activity_Resume
   
Activity.LoadLayout("listdesignerfile")
   
    MyMenu.Initialize(Activity, Me, "Collection", "Test", "L", 50dip, 400dip, Colors.Transparent, Null)
               
    MyMenu.AddItem(Icon, "List1", Colors.White, Colors.Transparent, 1)
    MyMenu.AddItem(Null, "List2", Colors.White, Colors.Transparent, 2)
    MyMenu.AddItem(Null, "List3", Colors.White, Colors.Transparent, 3)
    MyMenu.SetTitle(Colors.Transparent, Colors.White, Gravity.CENTER_HORIZONTAL, Null)
    MyMenu.OpenMenu("Fade")

End Sub


Sub Activity_Resume

StateManager.RestoreState(Activity,"LIST",0)

End Sub


Sub Activity_Pause(UserClosed As Boolean)

StateManager.SaveState(Activity,"LIST")

End Sub


Sub Click(SelectedItem As Object)
               
    If SelectedItem = 1 Then
        Activity.LoadLayout("listdesignerfile1")

    End If
    If SelectedItem = 2 Then
        Activity.LoadLayout("listdesignerfile2")

    End If
     If SelectedItem = 3 Then
        Activity.LoadLayout("listdesignerfile3")

    End If
   
End Sub
 
Upvote 0

Nb1320

Member
Licensed User
Longtime User
Guess I should mention that the only thing that statemanager is saving for me is checkboxes on each designer made file. :)
 
Upvote 0

Johnmcenroy

Active Member
Licensed User
Longtime User
The same error.
B4X:
trouble writing output: Too many field references: 69857; max is 65536.
Here https://developer.android.com/intl/ru/tools/building/multidex.html there is a solution
to overcome this problem, but for gradle system. But there is a solution for ANT system also:
1. Modify project build.xml file to support multidex. Here is an excellent modified build.xml file
with all needed: https://github.com/ruboto/ruboto-irb/blob/master/build.xml

OR

modify ant.jar (DexExecTask with parameter for multidex)

Also I saw that dexer.jar in B4A contains multidex classes.

Then two steps from multidex support tutorial for gradle:
2. Add to the project of B4A:
B4X:
#AdditionalJar: C:\Android\extras\android\support\multidex\library\libs\android-support-multidex.jar
Path - your path to this file according to Android SDK installation

3. Modify manifest file:
B4X:
<!-- MultiDex -->
<application android:name="android.support.multidex.MultiDexApplication" />
inside AddApplicationText tag.

Also info about that: http://stackoverflow.com/questions/27903059/enable-multi-dex-option-in-ant-for-android

But is this possible to solve part 1 in B4A ?
 
Last edited:
Upvote 0

ValDog

Active Member
Licensed User
Longtime User
I ran into this as well, and found a post which led me to strip down one of my libraries ("android-support-v4.jar") of functions that I was not using.
 
Upvote 0

jotaele

Member
Licensed User
Longtime User
I ran into this as well, and found a post which led me to strip down one of my libraries ("android-support-v4.jar") of functions that I was not using.

I do the same. Remove folders in the library jar files to decrease references.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi Erel, hi all.
More often I have this problem. If you working together some libraries (example: MsSql (Don), Google Maps, OkHttp, MSMaterialDrawer) is easily overcome the limit imposed 65536.
Is need to find a solution.
thanks
Marco
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
It is quite simple to reduce the size of google play services: https://www.b4x.com/android/forum/t...-apis-into-b4a-application.61537/#post-388268

This will probably solve your issue.

Embedding MsSQL jdbc driver in your app is a mistake in most cases.
Thank you for your reply Erel.
I use the library Don manfred (this great library uses this mysql-connector-java-5.1.34-bin.jar). I must use this library because, okHttp CANT work in the same wifi with more multiuser (when okHttp and use two or more users connect to the same DB in the same wifi you can not work).
I see your link, this is good solution if you need to solve the problem quickly. Isn't it better to find a solution that solves the problem ??
Thank you again and goo year
Great B4X ;)
Marco
 
Upvote 0

itgirl

Active Member
Licensed User
Longtime User
The same error.
B4X:
trouble writing output: Too many field references: 69857; max is 65536.
Here https://developer.android.com/intl/ru/tools/building/multidex.html there is a solution
to overcome this problem, but for gradle system. But there is a solution for ANT system also:
1. Modify project build.xml file to support multidex. Here is an excellent modified build.xml file
with all needed: https://github.com/ruboto/ruboto-irb/blob/master/build.xml

OR

modify ant.jar (DexExecTask with parameter for multidex)

Also I saw that dexer.jar in B4A contains multidex classes.

Then two steps from multidex support tutorial for gradle:
2. Add to the project of B4A:
B4X:
#AdditionalJar: C:\Android\extras\android\support\multidex\library\libs\android-support-multidex.jar
Path - your path to this file according to Android SDK installation

3. Modify manifest file:
B4X:
<!-- MultiDex -->
<application android:name="android.support.multidex.MultiDexApplication" />
inside AddApplicationText tag.

Also info about that: http://stackoverflow.com/questions/27903059/enable-multi-dex-option-in-ant-for-android

But is this possible to solve part 1 in B4A ?
That's is really a useful information but I don't think modifying the ant is a good idea but i think it would be great if we can use the first solution and use the build.xml
 
Upvote 0
Top