Search code examples
androidpythonsl4a

Android and Python


Can I port existing python scripts on android using SL4A or ASE ? What I specifically want to do is to create an android application with normal UI elements and run the python scripts from the application itself, get the output and display it. Is this possible ?


Solution

  • Personnaly I think that you ask implicitly for three points:

    Compatibility Desktop/Mobile

    The first is the compatibility between the python library on the phone and the python library in your computer. If you don't use third party library and be sure to include the extra python library provided by sl4a, you should generally be ok.

    Packaging

    The second point is about how to package a Python app for android. It can easily be done with a wrapper as well described on the sl4a website. In fact they distribute a copy of a chapter of a book about SL4A that describes how to do that. So that is possible, but bear in mind that the user will be required to install python if he hasn't done so already (this is a sort of alert at the launch of the app)

    UI

    The third thing that you should have in mind is that you are not a 100% free concerning the widget/layout you can use with sl4a. Namely you can't really do whatever you would be able to do in Java or Scala. So you might have to consider altering your UI and do a webview instead (that can communicate back and forth with the python) with a framework to obtain a "mobile look and feel"

    Hope this helps.