Android Question Cleanup unused modules

Alessandro71

Well-Known Member
Licensed User
Longtime User
When you perform a "Remove module" the actual .bas file is not actually removed from the project directory.
Over time I end up losing track of what modules are actually used in the project (my biggest project has around 200 files) so I need to manually check them out over the Modules tab in the IDE.
Is there a faster way, or an automation tool available?
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello @Alessandro71,

Is there a faster way, or an automation tool available?
I hear you.

This has previously been mentioned on the forum.

Personally, whenever I use 'Remove Modules', I always click a macro button (which I've added to open the project folder), then I remove the file manually.

The same with renaming modules I believe. I always double check the folder afterwards. Actually, I delete/rename, do a clean, then check the folder. It's become habit these days.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
Personally, whenever I use 'Remove Modules', I always click a macro button (which I've added to open the project folder), then I remove the file manually.
I do the same when I can, but there are some use cases where this can't be applied:
my project has multiple versions: B4A, B4i, B4J: sometimes a module is removed from one version only, but is to be kept in the other versions.
So a periodic cleanup, when the project is stable, is needed.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Find all active project files
Fortunately for you, a B4A project file, such as the 1.b4a of the B4X-Pleroma-master project, comes from a simple text file. If you open this in Notepad++, for example, you will see an overview of all modules currently in use.

Fortunately for you, a B4A project file, such as the 1.b4a of the B4X-Pleroma-master project, comes from a simple text file. To find out which files you are using, proceed as follows:

  1. First, make a full backup!
  2. Open the <projectname>.b4a file in Notepad++, for example.
  3. Scroll down to the line that starts with 'Module1='.
  4. Select all lines that start with 'Module'.
  5. Copy all selected lines.
  6. Open a new blank sheet.
  7. Paste the selected lines onto the blank sheet.
  8. Remove the text between the beginning of a line and the last \ character to keep only the filename
And you have all the actively needed files. Repeat this for the other IDE program environments and merge those list to one total list. Success with it.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I often find myself creating, say, a codeModule, with a given name, and then I realise that I need to change it to be a ClassModule, and I can't use the same name before deleting the file...
The same mechanism used for the "Added Files" should also be applied to modules... When you remove a file, you are given the option to delete it or not...
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I recently appreciated ANOTHER potential of B4X: macros, for launching your own jars.

Using what @MicroDrie wrote:
  1. First, make a full backup!
  2. Open the <projectname>.b4a file in Notepad++, for example.
  3. Scroll down to the line that starts with 'Module1='.
  4. Select all lines that start with 'Module'.

You could create a jar that cleans up the project and create a dedicated macro (it's convenient to put the macro in your project template or create a snippet).
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
I often find myself creating, say, a codeModule, with a given name, and then I realise that I need to change it to be a ClassModule
a bit out of topic but, over time I developed my own best practice for modules:
I use Code modules only for defining project-wide constants, and define a Class for everything else, even if it's a single instance object, mainly for 2 reasons:
1) code modules don't support events (Wait For)
2) code modules, when used in B4J Server projects, are executed in the main thread, thus preventing multithreading, while class can be executed in the thread that handles the request.
 
Last edited:
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
It's worth remembering that in B4J code modules are like singleton classes and support events.
true, this applies to B4A only, but since I work mainly on cross-platform project, I need them to work on Android also.

I also use code modules for another purpose: simulating Enums.
that's what I meant when I wrote "project-wide constants"
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
that's what I meant when I wrote "project-wide constants"
It's not exactly the same thing.
You could have a single code module with global constants and N "Enum code modules".

enmProf:
' enmProf - code module

Sub Process_Globals
    Public Const DOCTOR As String = "Doctor"
    Public Const ENGINEER As String = "Engineer"
    Public Const TEACHER As String = "Teacher"
    Public Const LAWYER As String = "Lawyer"
    Public Const DEVELOPER As String = "Developer"
End Sub

B4J_68wcarutiI.gif
 
Upvote 0
Top