Android Question Too Many Constants" error

Rick Harris

Well-Known Member
Licensed User
In Debug (Legacy) mode I still get a "Too Many Constants" error.
I have understood that the maximum number of constants is 65365.
Can someone please explain how to count the constants?
Better still: can B4A do a constants count?
Why does this problem not occur in Release mode? I.e. how many constants does the Debugger add to the total count?
 

Rick Harris

Well-Known Member
Licensed User
Thank you! 1. Will moving subs to libraries also solve the problem? I have the impression that it will not and that the variables that are used in the library add to the total constants count. Is this true?
2. Will splitting the activity in multiple modules als solve Debugger problems that are related to my very large app?
 
Upvote 0

Rick Harris

Well-Known Member
Licensed User
Compiling modules to libraries will help as the code in those modules will be excluded from the debugger (like all other libraries).


Hard to say.
Okay. Other question: Due to the fact that my main very large app keeps throwing up memory-related problems, I have moved some key features into a totally different App. This app gets started by my large app when needed and automatically returns to the large app when done. This is far from ideal because passing parameters from/to both apps is complex. Would it be feasible to move the sourcecode of this separate app back into the main large app by inserting it into a separate module? Or would adding it as a separate activity be a solution?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Would it be feasible to move the sourcecode of this separate app back into the main large app by inserting it into a separate module
Informatix ProBundle includes a ClassLoader which :
This library can dynamically load classes from a separate file (JAR or uninstalled APK) at runtime and verify the file signatures to make sure of its origin and integrity.
You can use the library to create plug-ins, load code encrypted in the assets or download code from a remote server, for example.
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Would it be feasible to move the sourcecode of this separate app back into the main large app by inserting it into a separate module? Or would adding it as a separate activity be a solution?
Memory issues are not related to the number of variables or modules.

You should add all the modules (including activities and services) to your main project. Note that in release mode there is no difference between libraries and source code. Compiling to a library can only help the debugger.
 
Upvote 0

Rick Harris

Well-Known Member
Licensed User
Memory issues are not related to the number of variables or modules.

You should add all the modules (including activities and services) to your main project. Note that in release mode there is no difference between libraries and source code. Compiling to a library can only help the debugger.
Thank you. Does it make any difference whether Class modules or Code modules are used in order to avoid the "too many constants" error? Which type of module would you recommend, bearing in mind that the source code of an entire (10,000+ lines of code) app would need to be moved back to the main app, if I follow your above recommendation?
 
Upvote 0

Rick Harris

Well-Known Member
Licensed User
It depends on your requirements. Code modules cannot handle events. They are just a collection of subs.

I don't think that there will be any difference related to the "too many constants" error.
Some time ago, on your recommendation, I moved about 10% of my code into a library. Wouldn't it be better to not use a library but in stead move all the library stuff back into a code module (in order to avoid the "Too many constants" error)?
 
Upvote 0

DonManfred

Expert
Licensed User
I moved about 10% of my code into a library
His recommendation was:
The solution is to split the large module into multiple modules.
You can move process globals from the problematic activity or service to one or more static modules.
He does not tell about a library.
 
Upvote 0

Rick Harris

Well-Known Member
Licensed User
His recommendation was:

He does not tell about a library.
I know, but please read the full discussion: I am having two problems that are related:

In thread #4 it was recommended to use libraries. This however did not solve my "too many constants" error (in Debug mode). In thread #8 it is now recommended to use modules. What I in fact want to know if this is a better solution, i.e. to forget about libraries and use modules in stead (which can also be used across various projects by placing the module in a common, shared folder). Moving a complete library to a code module can be done easily without the need to modify any subs.

Using libraries apparently is good for the debugger, however I cannot use the debugger(s) because of the "two many constants error"! I.e. Is there any/much difference between libraries and (shared) code modules, from the perspective of debugging and regarding avoidance of too many constants?
 
Upvote 0

Rick Harris

Well-Known Member
Licensed User
Sorry, I have already moved as much as I can to a library, but that had no effect.
I first still have to resolve the "too many constants" error before even attempting to use the debugger(s). Currently both debuggers do NOT work at all in my very large project.

Furthermore, the project is commercially sensitive and as a principle I won't let it out of my office, regardless of whom is involved. To be concrete I repeat my question: Will moving the library stuff to a code (and/or class) module solve the "too many constants" error?
 
Upvote 0

Rick Harris

Well-Known Member
Licensed User
I don't think so.
OK, but then I don't understand your recommendation in thread #8 where you wrote:
"You should add all the modules (including activities and services) to your main project" because thatwill only make things worse: The number of constants will presumably become even much higher! (Or am I wrong?).
 
Upvote 0

Rick Harris

Well-Known Member
Licensed User
The error you encounter is rare. I don't remember seeing any project with this error. The truth is that without seeing the code it is very difficult to guess what will help.

I can say general things like:

- Move code to compiled libraries.
- Don't mix code and data. Data should be loaded from files.
OK, thank you. One last :) question: Can you give me any insight what kinds of objects count as a constant (and thus contribute to the "too many constants error")? I assume:
1. Any variable defined under process globals and globals (?)
2. Each sub(name) (?). If so, does it make sence to reduce the number of subs (or combine/ avoid subs where-ever possible)?
3. Each defined variable in each sub (?). If so, is it recommendable to move variables from the subs to the globals and thus re-use them?
4. Arrays (?), but does each element in an array count as 1?
5. Each library (?) and each sub in the libraries (?)
6. Each defined variable in the used libraries (?)
7. Each code and/or class module (?)
8. Each defined variable in the used code or class modules (?) and each sub in these module (?)
9. Each service (?)
10. Each defined variable in the used services(?)
11. Used (loaded) Files(?)
12. Other?
 
Upvote 0
Top