paint-brush
You Can Build a Mobile App in Python but Packaging It Risks a Storm of Bugsby@oliveremeka
10,466 reads
10,466 reads

You Can Build a Mobile App in Python but Packaging It Risks a Storm of Bugs

by Oliver IfediorahJanuary 13th, 2023
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

Python is a very popular programming language due to certain desirable features it has; like readability, ease of learning, flexibility etc. It has become widely adopted in various fields or aspects of computer programming like scripting, web development, cyber security and machine learning. One field of programming where python is actually not widely used is mobile development. This is attributable to the fact that python is relative slow in execution (hence, python apps may struggle on mobile devices with low specifications) This article further explores mobile development with Python in relation to this packaging problem.
featured image - You Can Build a Mobile App in Python but Packaging It Risks a Storm of Bugs
Oliver Ifediorah HackerNoon profile picture

Python is a very popular programming language due to certain desirable features it has like readability, ease of learning, flexibility, etc.


Hence, it has become widely adopted in various fields or aspects of computer programming like scripting, web development, cyber security, and machine learning.


Python has many libraries and frameworks which adapt it to usage in these different fields e.g., Django and Flask are Python frameworks used in web development; Pandas, Numpy, Scikit-learn, PyTorch, etc., are used in machine learning, while Python libraries like Scapy, Beautiful Soup, and Cryptography are used in cyber security.


One field of programming where Python is actually not widely used is in mobile development.


This is attributable to the fact that Python is relatively slow in execution (hence, Python apps may struggle on mobile devices with low specifications), and also due to the fact that Python, being an interpreted high-level language, is far from and may not work well with the native language of mobile operating systems (i.e., Java for Android and Objective-c/Swift for iOS), which are generally compiled, mid-level languages.


This shortcoming of Python in mobile development is, however, a problem for many programmers as Python is basically the most popular first language for beginners in programming, and they may want to delve into mobile development which has become very profitable due to the billions of mobile devices being used around the world.


Also, professionals in Python who are already using the language for web development, artificial intelligence, or cyber security may also want to convert their software to mobile apps for one reason or the other.


It was certainly a problem I faced after learning Python and deciding to create mobile apps to get some of the scripts I had written to users who may find them useful.


However, while it is not popular to use Python for mobile development, it is not impossible. In fact, a couple of frameworks and libraries do exist for mobile development with Python, and a few have quite a sizable community.


Some of them are Python-for-Android, Pymob, PyQT(pyqtdeploy), Kivy, RenPi, and Beeware.


Some of these frameworks also inherit the friendly syntax of Python for UI development (e.g., Kivy design language). This makes Python a very useful mobile application development language when used for small applications or rapid prototyping.


A lot of problems, however, arise when trying to compile or package a finished Python app for mobile. At least, this was my experience with Kivy, and my research showed that it was a commonly experienced problem.


One reason for this problem is probably how often lightweight Python mobile libraries do not leverage the sophisticated debugging resources of Android studio to the extent that popular frameworks like Flutter and React Native do.


This article further explores mobile development with Python in relation to this packaging problem and the best practices to overcome them.

  1. Kivy: This is actually a cross-platform Python framework that allows users to create applications for windows, mac, Linux, Android, and iOS. Kivy uses a clean design language to develop UI which is similar on all platforms. It uses pure Python for the application programming and packages (e.g., buildozer is used in deploying the code to specific platforms).


  2. Pyqtdeploy: This provides a set of tools for packaging PyQt CLI and GUI applications or libraries to desktop and mobile devices. Projects packaged with this tool can be commercialized due to its free license.


  3. Beeware: This is a set of tools for building Python apps including Toga - a toolkit for cross-platform UI, Batavia – a Javascript handler, and Briefcase for packaging apps for mobile and desktop. Beeware apps have platform-specific look and feel.

The Packaging Problem

While the development process is often smooth and straightforward, packaging a Python app for any platform is often problematic. In addition to mobile, I also experienced this problem when trying to package a Python exe file using Pyinstaller.


The problem is further exacerbated when third-party python libraries are used in the application.


From my experience, this storm of bugs when packaging the application boils down to two major reasons:


  1. Python mobile development libraries have little or no support for real-time application development with Android emulators or Android devices.


    Mobile developers who use Flutter or react native will appreciate how helpful it is to use a virtual or physical device while building your application. This helps in discovering all kinds of syntax, runtime, and compatibility errors early for quick fixing.


    With python libraries, however, developers generally have to build the application on their desktop device before packaging the APK version for the mobile device.


    This can result in a lot of compatibility issues when the Android or iOS tools begin to interact with the code for the application.


    Hence, the problem is that an application that has been built for a desktop environment is being packaged for mobile.


    This may seem fairly obvious, but developers must keep it in mind when packaging a Python mobile application because the terminal may likely not point it out (as was the case for me).


    This can waste precious development time and could even frustrate the developer to the point of giving up.


  2. Use of Third-party libraries.


    I find this necessary to point out due to my experience; when trying to package a Python program, I created it as a windows executable.


    To my shock, while the program was working well on the Python terminal, I received incompatibility complaints from the third-party libraries when packaging the application.


    This can also happen when packaging a python program as a mobile application.

Best Practices to Overcome This Storm of Bugs in Packaging Python APK

  1. Expect that the terminal may not point out all errors present.


  2. Research the compatibility of the versions of libraries used.


  3. Build dynamic UI that can adapt to mobile devices without causing overflow.


  4. Use any available extra debugging commands for a detailed error report.


  5. Use debugging applications like logcat reader to get additional terminal reports when your app is running on your mobile device.