Wish Ability for compiler to remove uneeded lib and permission references

JohnC

Expert
Licensed User
Longtime User
To save development time, I have a Common.Bas file that is shared among projects. In this code module are various routines that I use often.

Many of the subroutines in this file either require a particular library or a certain permission. Because of this, I run into a few problems:

1) The project gets marked as needing certain permissions, when it really doesn't need them - the permissions are only invoked just because the project has a sub in it that uses those permissions, even though that sub is never called from the current project.

2) I get compile errors like "unknown type" because one of the subroutines uses a library, even though that subroutine is not called from the current project.

For #1, I could add a "RemovePermission" to the manifest, but I would have to do that manually and it takes time to figure out what permissions I *don't* need.

For #2, I could either move subs requiring the same library to another module file and simply don't include that module if I don need those subs, but that also is cumbersome and messy and results in MANY shared files. Or, I could use conditional symbols to selectively include certain subs or not, but that too becomes very messy and time consuming to figure out what keywords I need for a particular project.

So, it would be VERY helpful if the compiler could first do a first-pass of the project and temporarily remove all subroutines that are not used, then do the real compile of the project.

This way it won't error on unknown types for routines that use a particular type but are not called from the current project, and the project will only require the permissions it actually needs and not for permissions that a sub uses, but that sub is never called in the current project.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The compiler will warn you about: unused libraries and unused subs. The compiler will never remove them for you as the compiler cannot be 100% sure that the code is not called dynamically.

You can see which objects add which permissions by using the List Permissions button (in the logs tab).
Sounds to me that you need to use conditional compilation and exclude parts of the code based on the conditional symbols.
 

JohnC

Expert
Licensed User
Longtime User
With permissions, there are only a handful of them, so it is not too much of a hassle to use conditional compilation, especially when its rare when a new permission is needed to be added to a project.

But, due to the dozens of libraries available, it's not practical to use a conditional symbol to control each sub/lib to be included.
 
Top