Android Question CustomBuildAction Help

chrisinky

Member
Licensed User
Longtime User
I'd like to do a few things but struggling (though still searching) to see if I can find what I want to do here....
I'd like to provide a UI (be it B4J app, or VB.NET app, or powershell etc) that feeds from a list I provide that would look like:
CustomerName, FilePath, Server
TestCustomer, D:\customers\TestCust, app.testcust.com

When I build I'd like my UI to give me a drop down (easy part) from my text list that looks like above, when I select the customer I'd want the following to happen:
1. APK gets copied to the FilePath variable
2. Server gets set as a variable in the program before compile
3. I'd also like to append the Version# variable in the APK name if possible.

Is this doable? Is there documentation/examples of like I can study? Thanks!
 

walt61

Well-Known Member
Licensed User
Longtime User
I'd do that this way (not tested, so some refinements/adjustments may be needed):

1. Have a CustomBuildAction that runs your UI program to select the customer:
B4X:
#CustomBuildAction: folders ready, path_to_your_program.exe
That program should create file "server.txt" in the project's Files folder.

2. In your app's code, get the server name with:
B4X:
serverName = File.ReadString(File.DirAssets, "server.txt")

3. 'APK gets copied to the FilePath variable and append the Version# variable in the APK name':
Use '#CustomBuildAction: 4, ...' (i.e., before the APK is installed: https://www.b4x.com/android/forum/threads/modules-attributes.24721/) to run a console (command line) program (that you write, e.g. in B4J) to which you pass command line arguments 'project name' and 'project folder' (https://www.b4x.com/android/forum/threads/b4x-comment-links.119897) using '%PROJECT_NAME%' and '%PROJECT%' in the #CustomBuildAction command. (If you'd only use this approach for one specific project, you can even hardcode those values in that program instead of using command line arguments.)

Knowing the project name and folder, you can
- read the .b4a file (it is a text file) and determine the app's version by looking at the lines that contain '#VersionCode' or '#VersionName',
- and then copy the apk file from the Objects folder to the folder specified in environment variable 'FilePath'
 
Upvote 0
Top