Skip to content

Step by step guide to create an Android application using PythonFMXBuilder

Priyatham edited this page Aug 20, 2022 · 6 revisions

Environment Setup

PythonFMXBuilderGUI_Debugger_Settings

Now the environment to build an Android application is set.

Project Setup

  • Click on the option Project > New project in the Project explorer section. Enter the name of the Android app that you want to build here. I've set it to Frames here as we're using Frame component of DelphiFMX package:

Builder_New_project

New_project_window

  • You can check the "Create Main File" option if you want the Builder to create a default main script file for you.
  • Add your Python script files and any other supporting project files that you use to create your application. One of the best practices is to take a modular approach in building your application. As per the modular approach, we can write all the implementations in separate Python files and call them from the main application Python file. Here, I added the frames.py and frames_main.py files from our GitHub samples using right click on mouse > Add file on the right-sided Project explorer window. Here, the main application file is frames_main.py;

proj_files

  • You can open the files in the editor area by double-clicking the above added files;

PythonFMXBuilderGUI_editor

  • Update the project settings by going to Project > Update Project:

PythonFMXBuilderGUI_Update_Proj

  • It opens up a slider window from the right edge to set up all the Project details.
  • You can see the name of your application is already set in the Application Name and Package Name fields. In my case, it is Frames, which we've set at starting:

image

  • Provide the version information in the Version Info section. It depends upon your release schedule information.

image

  • Let's set up the main file that can be used to run our application in the Initialization Script Setting section. Here, we're setting the frames_main.py to the main file from our two script files.

PythonFMXBuilderGUI_Init_script

  • We're shipping 3 Python versions - 3.8, 3.9, and 3.10 as part of the PythonFMXBuilder release. They're compiled on Android-NDK to support Python code on an Android device. You can choose one of those versions in the Python Settings section. We also support building apps on both 32 (arm) and 64 (aarch64) bit arm architectures.

image

  • You can set the app icon and splash screen (app start screen) image using the Application Icons section. Based on the device screen sizes and screen densities, FMX Builder will choose the image size of your splash screen and icon. You can upload all those sizes to support all screen sizes and resolutions.

PythonFMXBuilderGUI_App_Icons

Note: After setting all these Project options, press the Save button at the bottom.

Connect your device

First, you need to activate USB Debugging on your phone. To do that;

  • Open About Phone in your Settings, Open Version and press few times on the Build Number. It shows a message that "You're a developer now". * Then, open Developer Options and activate USB Debugging.
  • Connect your phone to the computer using a USB cable. It asks you for permission on your phone to "Whether you want to allow USB Debugging on the connected computer?". Press Allow.
  • Then click on the reload button to load list of devices and select the first device using this "Load Devices" button on the right top corner;

image

Debugging Applications

We're super excited to say that the FMXBuilder application supports most of the debugging features of modern-day IDEs.

Note: For debugging functionality to work, you need to install the TMS FMX UI pack. You can find it at: tmssoftware.com/site/tmsfmxpack.asp. Otherwise, you can build the raw Memo editor version provided in our release at Release v0.7.0 - Embarcadero/PythonFMXBuilder.

  • For debugging, you can set breakpoints at any part of your code by clicking on the line number wherever you want to debug and investigate.

Screenshot 2022-08-18 234138

  • Click on the Debug Project button to enter into debug mode and start debugging the application.

PythonFMXBuilderGUI_Debug_icon

  • In the debug mode, multiple windows to support debugging will be opened. They are:
    • StackTrace
    • Local Variables
    • Events
    • Breakpoints
    • Threads

Screenshot 2022-08-18 235027

Local_Variables

Screenshot 2022-08-18 234138698

Breakpoints

Threads

  • You can use the multiple controls that are activated in the Debug mode. You can use them to navigate through the debugging process. Each button's functionality is self-explanatory.

debug_controls

  • After you're satisfied with your debugging, you can press one of the Stop or Continue buttons of the above buttons to finish the debugging process.

Building, Deploying and Running Applications

We're providing three options for the developers who build applications using PythonFMXBuilder:

PythonFMXBuilderGUI_Run_Menu y

  • Option 1: Build an Android application (.apk) file. You can share your .apk file in your internal groups for reviews and validations. To do this, press on the Build button, which generates the .apk file in path\to\FMXBuilder\GUI\Folder\apps\Frames\bin folder in my case.

PythonFMXBuilderGUI_Build

  • Option 2: Build and *Deploy the application to your device directly using the Deploy button:

PythonFMXBuilderGUI_Delploy

  • Option 3: Run button will implement both Build, Deploy and Run (Launch) your application at once so that your app opens up as it launches.

PythonFMXBuilderGUI_Run

You'll see your application open up on your device or emulator automatically as you Run it. You can iteratively develop for changes in your app and Run to build any Android application of your choice.

Clone this wiki locally