VBScript to automate creating different builds

Kevin

Well-Known Member
Licensed User
Longtime User
I mentioned something like this the other day and today I finally decided to make this. It's probably not suited to everyone, but if there are others out there that change certain settings (such as Include Debug Information) or change package names, App Label, or the value of a couple variables depending on which "build" they are compiling, then this script may come in handy.

It does take some setting up, but once it is set up for your situation, it makes it much easier to quickly create your custom builds without having to do it manually or run the risk of forgetting something. It is written in VBScript and uses "sendkeys" to make changes and initiate compiling. Since there is no way for the script to know if things are successful, it simply assumes everything is working as expected. Also, if certain things change in B4A, it may break the script.


Script commands:

ToggleDebugInfo - Toggles the 'Include Debug Information' option in B4A. WARNING: There is no way for this script to know the state of it prior to toggling, so be sure that the beginning state will always be the same, or don't use this command.

BuildName - You can name your "build" here and it will be displayed in the script's output window. This is for your information only and does nothing to your B4A project.

JumpToHome - Jumps to the beginning of the code window in B4A. Handy when you want to ensure that B4A starts searching (to replace variables) from the beginning of your code.

ChangeVariable {ORIGINAL VARIABLE}, {NEW VARIABLE} - Changes a variable in your code. Certain things are expected as follows:
1) The original variable you enter here must be followed by a space and 'AutoBuild (See the example code below for more info)
2) This script will automatically add the space and 'AutoBuild to the variable you use in this script.
3) This is done this way to help make sure that ONLY variables you want changed will be changed.
Sample Script Code: ChangeVariable "'DemoVersion =", "DemoVersion = True"
In this example, the actual original line in the B4A project is: 'DemoVersion = 'AutoBuild
After the script changes it, the new line in the B4A project will be: DemoVersion = True 'AutoBuild
Assuming you use this same uncommented variable in your code for your default testing while programming and that it is above this AutoBuild variable, uncommenting and setting this special AutoBuild variable will override your default variable value in the compiled app.

SetPackageName {PACKAGE NAME} - Sets the package name for your project.

SetAppLabel {APP LABEL} - Sets the App Label for your project.

CompileProject - Compiles your project

CreateAPK {APK NAME} - After the project is compiled, this command will create a copy of the resulting APK and rename it as specified. It will be located in the 'build' folder, along with your originally generated APK. If this file already exists, it will be overwritten without warning.

Setting up your app for changing variables:

In order to ensure that ONLY variables you want changed are affected (when using the Search & Replace function in B4A), it requires variables to be entered in a certain way in your code as in the following sample:

B4X:
'* Demo or Pro
DemoVersion = False ' **** True if Demo, False if Pro  (DEFAULT WHEN PROGRAMMING)
'DemoVersion = 'AutoBuild   ((( used when automatically generating builds with VBScript )))


'* Android or Amazon App Market?  (Affects the 'Rate this app' and 'Buy Pro' features)
AppMarket = "Amazon" ' **** "Android" or "Amazon"  (DEFAULT WHEN PROGRAMMING)
'AppMarket = 'AutoBuild   ((( used when automatically generating builds with VBScript )))

In the code example above, when I am working on my project, it automatically defaults to the PRO version (that boolean value controls certain features in my app) and the AMAZON version of my app, which affects links to the market and 'rate this app'. Normally the AutoBuild variable are commented out, so they do not affect me when working on my app. When I run my script to create my special builds, by uncommenting those lines and changing the variable's value, it makes my app behave how I want it to for those builds.

So for example, you would tell the script to replace 'DemoVersion = with DemoVersion = True (or False), and it will only replace the variable if it is followed by 'AutoBuild. This is to ensure that it doesn't accidentally change similar code accidentally.

The script knows what to search for because you define it, but the caveat is that when you edit the script, you must make sure that you know what the variable should be before you change it. If the search text is not found, it throws off the script. This is the part that needs to be carefully setup.

So in my example above, here is an excerpt from the VBScript:

ToggleDebugInfo ' Leave Debug info out of the final build (normally this is on when programming)

' -----------------------------------------------------------------
' CREATE BUILD (DEMO for ANDROID)
BuildName "DEMO for ANDROID" ' Info for script window output only!
JumpToHome
ChangeVariable "'DemoVersion =", "DemoVersion = True"
ChangeVariable "'AppMarket =", "AppMarket = " & QT & "Android" & QT
SetPackageName "com.cognitial.directvremote"
CompileProject
CreateAPK "DirecTVRemoteFREE_AND.apk"
' -----------------------------------------------------------------


I created this for myself but figured it might be useful to others, which is why I am sharing it here. I tried to make it as simple to use as possible, but I admit it might be a bit confusing. The script needs to be located in your project's main folder (where the B4A project file resides). The script does create a backup of your project file before making any changes, but until you understand how it works, I'd use a backup of your entire project folder.

The script will also ask you if you have a device or AVD connected with B4A before it begins. This is so that it knows if it needs to clear the warning dialog seen after compiling when no device is connected.

If you find it useful, enjoy. If not, just ignore this thread. :sign0089:

** The VBScript file MUST be edited to suit your situation BEFORE trying to run it. It can be edited in any ordinary text editor. **

EDIT: To add that the script automatically closes dialogs coming from B4A. Do not do anything in B4A or acknowledge any messages until the script is completely finished.
 

Attachments

  • B4A_AUTOBUILD.zip
    3.2 KB · Views: 246
Last edited:
Top