Python and Android - android

This link says that it is indeed possible to write code in Python and use it for app development in android platform. I would like to know what the catch is when using Python and not Java. Is there any compromise being made in speed of execution or size?

From the link you posted:
Scripts can be run interactively in a terminal, in the background, or via Locale.
This already is a disadvantage, as you can't release your Apps to Android Market easily. This can however ostensibly be avoided by the build script of Pygame Subset for Android, but I am not sure about this. The Python interpreter will however need to be installed on the device, which will bloat the App's size by quite a bit.
The speed of execution of Python on an Android device of course is slower than Java, as Python doesn't magically accelerate just because it runs on a phone. The difference isn't that great in most situations, though.

Related

How to predict performance of a program for smartphones developed on a pc

I am developing a program that is going to be very performance-intense for Android/smartphones. Because I do this on a pc (Windows) I do not really know how my application will perform on a mobile device. I do not want to port this program to android until I have a good working version for Windows (this will be my first Android-app and I don't want to try to troubleshoot something when I'm not even sure whether my program is working).
I am searching for some database where I can compare pc-GPUs with mobile GPUs. I know that an accurate comparison is difficult between such different architectures, however, a small hint about the expected performance would be very helpful.
By the way, I am developing on a machine with an integrated IntelĀ® HD Graphics 4400 and ideally, I want to compare it to something like an Adreno 306.
Rather than using benchmarks for the GPU, look at existing cross-platform applications with similar performance and see how it compares. Install it on your computer to make sure the intensiveness is similar (using whatever benchmarks you want), then install it on your android device to see if it can keep up to your expectations. You can find benchmarking apps or you can use the profilers on Android Studio to see how the device in question is handling the application.
This is about as good as you're going to get. Like you said, so much relies on the implementation and the vastly different architecture. Lastly, if you're building on a framework that builds to other platforms (libgdx, xamarin, etc), you should present a specific question to other users of that framework.

Recording on the Mac machine Android scripts for appium and run them on the Windows machine using Appium

Since Appium's inspector is not conducive recording scripts on Windows, I am using AppiumForWindows coupled with uiautomatorviewer from SDK time to identify app objects and actions to send. I know that we can easily use recording option on Mac in order to record the flow and run it on Mac using appium.
However, I wanted to know if i can switch to Mac just for recording my android app script on the Mac machine and go then to my favourite windows machine for running them using appium? I cannot test now because I have not Mac yet. I told myself that it is possible because of the use of java language (multi-platform) and the fact that Appium provides a standard API both Android and iOS for automation but at the same time, I have doubts because of that answer, I have found on line at https://discuss.appium.io/t/can-we-record-the-script-on-mac-machine-using-appium-tool-and-re-run-the-recorded-script-on-android-or-window-phone-using-appium/5938
I want to decide myself finally. Please i want to know what you think about.
Yes and No, Appium api's are cross platform compatible, however the id's and paths which you use to locate the object under test in both platforms are different, which could cause the script to not work.
I have not used the recorder as such, however if both apps are exactly similar, one could create same test case, with maximum reusable in locating an object by accesibility tag (provided both are kept the same).

Running an Android phone as a stable webserver (for a Python CGI script)

I'm new to Android. I have a Python program that is both a CGI script as well as an SMS-based interaction system for a small database. It is an extremely low demand system (a handful of users) being run by a grassroots organisation. But it requires stability, in the sense of not having random crashes or down time. For various reasons, running this on an Android phone would resolve some problems with the existing setup. However, before I dive in, I wanted to check regarding the feasibility of such a system. It would have to:
Run a web server that could execute CGI scripts (vanilla CGI)
Respond to SMSs
Handle an SQlite database
Do so in Python (as porting it to Java is not feasible due to time constraints)
Interfacing with phone users is not required at this stage.
I am aware that the pieces that would be needed exist - web servers with CGI, SL4A, etc. But the webservers mostly seem intended for personal use and SL4A clearly states that it "is alpha quality software". The various questions on SO relating to SL4A also don't seem to say much on this kind of use case. They are focused on application development for phones (such as this one).
In short, would such a system be stable? Assuming the core program is sound, could I rely on it?
TLDR: CherryPy is a dependable server, and Android may be dependable enough to build servers on these days.
I used to maintain a project that used CherryPy and SL4A (with ws4py for websockets).
CherryPy 3.2.2 worked perfectly on Python 2.6 and Python 3.2.
The application was often running for a day or two. It seemed like it would have been fine if it ran longer, but it got restarted a lot as it was being developed.
CherryPy was always fine, but Android devices do sometimes just crash, so SL4A will exit from time to time, and need to be restarted. This may not be an issue on a device that was only used as a server. For me, it was always stable when the device was left running overnight, but would occasionally crash when I was using the device normally (it was my actual phone). All of this was on a Galaxy SII, back when Android was still pretty buggy like that.
Setting up CherryPy is easy. It's pure Python, so you can just drop a copy onto your path some place and import it (you do not need an emulator either).
You may struggle to keep the device awake. If it is left alone, it will go to sleep. You can tell it to stay awake in the developer options, but I am pretty sure that only works if the device is charging.
UPDATE: Android is much more stable now days, but work on the SL4A project has pretty much ended. There's a project called QPython that maintains SL4A as part of a bigger app, so this stuff can still be done.
For running Python CGI scripts in Android. Basically you needed a web server capable of running CGI scripts in Android platform but, I found none. You need toy CGI script to suit the Cherrypy web server and it could run on Android.
Are steps are here :
First thing we need is to download the SL4A (r4) software in the
Android (2.3) emulator. It can be done from your Android browser by
going to the SL4A site. Now install the software in emulator.
Then install Python for Android from the same SL4A site. It'll
download an apk of version r4.
Launch SL4A application and check that HelloWorld python script is
running. It will make sure that your installation is fine.
Now is the time to install Cherrypy library module. It can be found
at http://www.cherrypy.org/wiki/CherryPyDownload. I have taken 3.2.0
version. Download the egg for python 2.6.
Now we need to transfer the egg file to Android emulator. Use adb
push command to transfer the egg file to /mnt/sdcard/Download.
Launch Python for Android from emulator and click on Import modules.
It will list the newly uploaded egg file. Select it and install.
Now we can write a Cherrypy script to be run as CGI. Below is a
HelloWorld example taken from Cherrypy tutorial (modified a bit)
# Import CherryPy global namespace
import cherrypy
class HelloWorld:
""" Sample request handler class. """
def index(self, **params):
# CherryPy will call this method for the root URI ("/") and send
# its return value to the client.
for key in params:
print key, '=', params[key]
return "Hello world!"
# Expose the index method through the web. CherryPy will never
# publish methods that don't have the exposed attribute set to True.
index.exposed = True
# CherryPy always starts with app.root when trying to map request URIs
# to objects, so we need to mount a request handler root. A request
# to '/' will be mapped to HelloWorld().index().
cherrypy.config.update({'server.socket_host': '127.0.0.1'})
cherrypy.config.update({'server.socket_port': 8080})
cherrypy.quickstart(HelloWorld(), '/')
8> The script needs to be transferred to /mnt/sdcard/sl4a/scripts directory in emulator. Then you can launch SL4A and tap the script to run. Debug outputs are visible if you run in SL4A console.
9> From the Android browser, check the URL http://localhost:8080/. It will say "Hello world".
This the web server set we can place python scripts to access Android phone data and other stuff which can be exposed to the outside clients.
Credits to: see the screen shots here
Other Info:
micro-httpd (GET / POST / CGI support) cross-compiled to Android
python-for-android
Running "Hello, world!" as a CGI Script
What I recommend:
I suggest to go for any lightweight web servers (like node.js) in raspberry pi
Ref:
Raspberrry pi python
lightweight web servers
web application framework for Node.js
Here is a link to one of my blog posts describing how to turn your android phone in a basic CGI webserver using Py4A / SL4A in around 10 minutes http://matbaker.wordpress.com/2013/01/29/android-webserver-in-10-minutes/
Your application requires running a server, which presumes constant availability, connectivity and unrestricted processing power. A mobile phone provides none of these.
Mobile phones are designed to conserve battery life by minimising processing and power demands. These two points are directly at odds with running a server.
But it requires stability, in the sense of not having random crashes or down time.
Assuming your software is correctly written, you may not have to worry about crashes, but the OS will be constantly trying to put the system to sleep.
Run a web server that could execute CGI scripts (vanilla CGI)
Respond to SMSs
Handle an SQlite database
Do so in Python (as porting it to Java is not feasible due to time constraints)
Why not just use a small virtual server? You can easily purchase a server for as little as $5 a month (e.g. DigitalOcean) and use Twilio as an SMS gateway (a few cents per SMS). Cheap, available, reliable and highly available. You get a preinstalled Ubuntu image, install a few extra packages on there and away you go with Python and SQLite. And you don't have to worry at all about the mobile/SMS side of things (signal strength, network availability, etc). All these points above would be satisfied by this solution.
If you don't want to operate a server externally (ie. "in the cloud") then you could use an old PC and install Linux. Or even use a plug computer and have an almost invisible server. There are so many hardware options that are more suitable than a mobile phone.
For various reasons, running this on an Android phone would resolve some problems with the existing setup.
How? What is it about Android that makes it preferable? If you're referring to the laptop battery problem, the phone would suffer a similar (if not worse) fate.
In short, would such a system be stable? Assuming the core program is sound, could I rely on it?
You will probably be fighting the OS and the hardware the whole time. A server wants to be running constantly, a mobile phone wants to be running as little as possible. The entire stack of hardware and software is optimised for power conservation. A mobile is designed to run from a battery with intermittent charging, and its thermal management systems are designed to wake the CPU as infrequently as possible. If you try to run a mobile as a server, you will likely wear out the hardware very quickly. They are simply not designed to run 24/7. You could run such a system, and it would probably work for a while, but I expect you would have to replace the hardware before too long.
Use hardware suited to the task of running a server. Old PCs are so easy to come by these days, it should be possible to get one for free that would be up to the task.
Also, is CGI really a requirement? You should really look at WSGI; it is far more efficient. CherryPi is a nice Python server, and Flask is definitely worth a look too.

Python and Android apps

I've been using Python for about a year now and would love to start writing some Android apps using Python.
I've been researching both Kivy and SL4A and I'm a little confused about something.
When you develop an Android app using Python and one of the above, does the user of the Android device need to download anything special in order to run? Or is it all transparent to the user?
Thanks
The user doesn't have to install anything, it's all transparent to the user, but keep in mind that the .apk will contain a full python installation, and thus you simply can't write apps that take less than about 10MB.
On Google Play there are some sample applications made with kivy, for example there is a touchtracer app that you may download to see if kivy would work on your device.
kivy requires OpenGL ES 2.0 for graphics, which is not always supported, even though most modern smartphones support it(I have a chinese B63M and kivy works fine with it).
The OpenGL ES 2.0 support is provided in Android 2.2+.
You may find other information about packaging for Android in this answer.

Using an android phone for development on the go

I'm always tinkering with new ideas, and sometimes I only have my phone with me. I played with ASE awhile back, but had a hard time typing much code with the limited editor, and only dynamic languages were available then. I have seen touchqode, and I think it's a neat concept to be able to compile and run on a server.
Are there any usable toolsets for doing development directly on android? Particularly, it would be nice to see a basic android development environment entirely on android as the host.
Are there any usable toolsets for doing development directly on android?
You already rejected all of them in your answer. IOW, the only significant on-device development that I am aware of is SL4A (formerly known as ASE).
Note that with SL4A, you are not limited to it's own editor, so you might wish to poke around the Market and see if there's an editor that you like better.
Particularly, it would be nice to see a basic android development environment entirely on android as the host.
You are welcome to start porting the JDK and the Android build chain to ARM. This may take some time.
AIDE lets us compile apps from Android. Looks like it didn't take as long as some thought.
Things have changed, so I wanted to update my original question to reflect a better answer.
Considering the limitations of these devices I think it's wishful thinking to have a full-blown development environment. But SL4A + python is quite amazing. Not a toy.
A small improvement to SL4A is to use the "Hackers keyboard" available from the market which can be customised to take much less vertical space than other keyboards. For me, this makes a large practical difference. Plus you can do the bulk of scripting from a computer: adb has a port forwarding option that integrates with the android python module and SL4A in server mode so that you can develop in a python environment on your pc but have the android stuff execute on your phone. You can also shell into the phone from adb and use vi to edit scripts. And then you can do tweaking from your phone, having done most of the scripting in a more comfortable environment.

Categories

Resources