Can python build android apps? - android

I am learning python and i don't know that it will be helpful to me if i want to make android apps.I have read somewhere that python can make android app.But I want to ask you that is it a good option or we should always use andriod studio to make android apps because that is developed particularly for creating android apps.

I'm a core developer of Kivy, which has been mentioned in some of the other answers. I think it's the main option you have for making python apps for android, and it has both advantages and disadvantages.
The main technical disadvantages are (both in my opinion and I think the main problems I see people raise):
Startup speed: if the app isn't already running it takes a short time to spin up the python interpreter, up to a few seconds on older devices (or much longer if you code some things badly but that's avoidable), during which time a loading screen is displayed.
Lack of native look and feel: Kivy is its own opengl-based graphical framework, so it doesn't look like default android apps (it's customisable but still very hard to perfectly emulate something like that)
APK size: Because you have to package the python interpreter, the minimum apk size is about 7MB.
Ther are other potential disadvantages, such as the standard non-java problem of having to catch up the android api when it changes, but I consider these more minor issues, e.g. in this case since you can actually call much of the java api directly from python with pyjnius. I have a blog post about this. Another problem is that kivy's community is small compared to that of the java app community, though it's also quite active.
For some people, one or more of these are immediate or eventual barriers to using Kivy. For others they don't matter or are outweighed by the advantages, and for these reasons there are people using Kivy commercially on Android (and iOS). Personally I'm most interested in the wide space between 'I wrote a simple script' and 'I made a big polished android app', because I think it should be easier than it currently is to bundle simple things as simple apps, but that's just my own reason for using kivy.

If the question is,can i run python programs on android then by all means yes.
But if the intent is to create a mobile app usibg python then please look at kivy which is yet to support python 3.
But outside the love of python ,its best to stick to android studio for native android apps.

Chaquopy (https://chaquo.com/chaquopy/) is an option for Python on Android. It is a plugin for Android Studio so could include the best of both worlds - using the Android Studio interface and Gradle, with code in Python.
From the Chaquopy page:
With the Python API , you can write an app partly or entirely in Python. The complete Android API and user interface toolkit are directly at your disposal.
A in-depth review of Chaquopy is at http://blog.codelv.com/2018/02/a-look-at-chaquopy-python-sdk-for.html
The creator of Chaquopy also commented on that review with this:
I think there's room for many different approaches to Python on Android. Chaquopy focuses on giving complete access to all the features of the standard Android API and build tools. (For example, the XML layout file you mentioned was generated using Android Studio's WYSIWYG editor: it didn't have to be written by hand.) But if you want something more Pythonic, or portable to other platforms, then enaml-native or Kivy is the way to go.
CAVEAT: I have not (yet) tested this personally, so I cannot verify how well it works. It is rather complicated.
Additional: It appears to require a license key to run for more than 5 min and requires payment. If you decide to develop open source, there is an open source license which "will always be free of charge."

try kivy https://github.com/kivy/python-for-android
It can be used to create android apps.

Android doesn't come with a Python interpreter. So if you want to distribute an application written in Python, you will have to bundle a Python interpreter along with it. In other words, even a "Hello World!" app will be huge.
So yes, it's possible. But not recommended.

Yes you can using
1- Kivy library
2- install Ubuntu on a versatile machine
3- run buildozer to transfer your main.py file into APK file

Related

Python - Does Kivy implements activities in the Android apps?

As we all know, when developing an Android app in native Java, we use activities. I was wondering that, in developing Android apps in Python(with Kivy), does Kivy implements activities for the apps in itself or not? because I don't see any activity implementation on the sample codes.
If it doesn't implement activities, Do we lose performance or any functionality in the application compared to coding in native Java?
Simply put, you can use Activities (starting them using pyjnius), but not really define them, at least, it's not usually the way one work with kivy.
Kivy doesn't adjust its way of working for targetted platform, it uses its own systems, and make them work there. For what i know the advantages of separating Activities on android is just a way to make your code more neatly organized, and doesn't imply performance changes. It can allow you to start your app in various ways (from a share, for example) but you can do that with p4a/buildozer too, by dispatching messages about the intent, if you need to. With kivy, you'll organise your code like you would do for any python project, using modules.
Kivy is a great tool for developing Android Apps. The best advantage of using Kivy is that it is cross platform and the same project can be used to publish apps on mutti-platforms.
However , it has some performance related disadvantages(as do most cross-platform tools like unity , cocos etc). If you're developing only for Android , I'd suggest taking a look into development tools which use Java. This will help create a smaller APK file which in turn helps in better user retention.
I guess you are real loyal fan of Python, but I have to tell you about its advantage and disadvantage.
Advantages
Pure python and its almightiness is in your hand.
Relatively simple to deploy with buildozer without any need to dive too deep into the details of particular platform.
You can run your app on desktop also, so there is no need to install some extra emulators/VMs to get it work
Disadvantages
Not that much information in Internet, even on stackoverflow
Pretty messy documentation
No obvious way to test the application
Not obvious machanisms of placing widgets, especially in built in layouts, which causes situations like: you want place widget in the center of it's parent, but kivy places it anywhere but not where you want it to be.
Official examples are quite ugly, so you may get false vision of how your application could look like.

kivy or something else for android UI

I am learning to program (python 3.x) and was wondering what would be best to learn for making android apps/games. I dont know anything about UI really but have heard that kivy? Is on android. Is that worth learning or should i use something else.
Thanks
Edit:
I am using sl4a and py34a on my android device.
Kivy is good, and will run on Android, but you can't make Android apps with it. It has no way of interacting with the Android API. You can run a kivy app on the device, but can not read sensors or anything like that. They have a project called pyjnius, which allows you to access Java classes from Python, but not with Python3, and it's not very easy to use unless you know Java.
You have SL4A installed, so you can use web technology to do UIs, including games, which can be rendered on the device using webviews. That said, Kivy is a much more mature and well maintained project.
I'm loving kivy. The irony is, that I found this topic here looking for help with python 3. Python 2 works perfectly, but 3 is still being made compatible. Other than that Kivy is great for beginner coders. Especially, because you don't have to code the complex stuff.

Difference between Kivy and PY4A

I'm new to android development, and I have had some experience with Java, C#, Python, etc. Python being my favourite, I'd like to code Android app with it.
Then I saw this question:
Is there a way to run Python on Android?
The most voted answers mentioned Kivy and ASE(which is now SL4A and includes PY4A).
However, after some googling, I wasn't able to find any useful info about the difference between Kivy and PY4A. Searching for difference between Kivy and SL4A was fruitless, too.
So, as for Kivy and PY4A,
can someone explain, in easy terms:
- What are the similarity and difference between them?
- What are their good and bad parts?
- Are there any other good alternatives?
Confusingly, there are two projects called 'python for android'.
SL4A lets you run python scripts on android. Their PY4A is a step in their toolchain, but I don't know much about it. I understand there is some integration with android apis (you can use some hardware etc.), but limitations in how to run the programs (they aren't full apps, no gui etc.). This is stuff I infer from seeing other posts, I haven't tried it, don't take my word on the details. (Edit: actually it seems there is some ability to package apks and multiple ways to create a gui, I don't know the details)
Kivy is a graphical framework that supports many operating systems (linux, windows, osx, android, ios, maybe more already). You use it to build python guis. The kivy project also started their own python-for-android project which provides ways to compile the python interpreter for android and to package it as an actual android app (including java api integration with pyjnius etc.). Kivy is well integrated with it so that you can easily compile a python gui app for android, though I don't think this python-for-android is limited to kivy apps.
So, they are completely different projects that happen to have a component with the same name. SL4A is for running python scripts on android, I don't know much about its limitations or details. Kivy is a python graphical framework (not limited to android) that can be compiled via its own different python-for-android project to fully integrated gui android apps.
You can see (for instance) kivy showcase for examples of some simple kivy capabilities, or flat jewels for an example of a simple game made in kivy. These are just examples, a lot more is possible.
I've found this very useful (and recent):
Embedding Python in Android (Tutorial series)
http://techventura.wordpress.com/2014/04/21/embedding-python-in-android-series/
It describes how to embed Python in an Android app, using the Kivy-related Python-for-Android, but not Kivy itself (which isn't really described in Kivy's nor Python-for-Android's documentation, as far as I found), which is useful in various scenarios (e.g. existing Java app, using native GUI directly, etc.)
Since Kivy's Python-for-Android is more actively developed than SL4A(ASE)'s Py4A, it seems to me the way to go.
(I think it would be very relevant also, and probably more appropriate, to Is there a way to run Python on Android?, but to answer requires more reputation than I currently have.)
To the point of the original question: the most relevant difference I see between Kivy's Python-for-Android and SL4A(ASE)'s Py4A is that the latter is still today offered as "alpha quality", while the former seems to be far more active.
Of course if you take Kivy as a whole, it's a cross-platform GUI library.
Also, the results of my research on the various solutions:
Google's Py4A + SL4A(ASE) : used but alpha quality, not actively developed
Kivy:
offers Python-for-Android, to call python code from Java
offers Pyjnius, to call Java code from python
seems to be actively developed
there's the tutorial I linked above to embed into Java Android app
if interested, the cross-platform GUI (Kivy itself)
QPython:
primarily an interactive environment to launch python scripts on Android
based on Py4A, but Pyjnius (see above) is said to be usable
embedding into a Java app is available, but somewhat limited: a Python job must be started with an Intent, and results are gathered from the stdout; that means more separation that could be desirable in some scenarios, I think.
python.org: no mention at all of Android
Have you tried QPython ? It's a new python for android instance which offers more functions.
In addition to the answers here, I'd add the fork of the original Py4A which seems to be actively developed: https://github.com/kuri65536/sl4a
I can't vouch for the quality or the ease of use. There are .apks to install so it seems fairly straightforward.

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 ?
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.
I think, what you want to do is make an independently apk file, that includes the python interpret and your script code.
I don't know if this can be done in Android. The only whay I know is running your script from Android Scripting Environment.
If web interface is normal UI then look at this discussion http://groups.google.com/group/android-scripting/browse_thread/thread/f86812549d2686e2/f828f916411d7a95 . You can use Python, webView, HTML5 and JavaScript
I had a similar problem and finally solved it by writing a small singleton class in Java that runs the Python-4-Android binary from the SL4A installation in a subprocess created using java.lang.ProcessBuilder. So I'm not using the SL4A mechanisms at all (triggers, upcalls, etc), just borrowing Python.
This seems cleaner than trying to start and connect to a Python process through SL4A.
This is Python 2.7.1, cross-compiling extensions from Mac OS X Snow Leopard. My Python modules are doing only text input and output, accepting socket connections, etc. No interaction with the Android API. It all works fine: writing a Java stream to Python input and reading a Java stream to get Python output. C extensions are build using the P4A instructions . (Android could not find .so dynalibs until I added
[build_ext]
inplace=1
to setup.cfg during the build. I think this is because setup 'install' is never invoked on the Android. I'm just pushing with adb.
All the activity lifecycle states seem to be working, but I can't yet determine whether the sub-process is automatically suspended while the main process is in the stopped state.
I can post code in a couple of weeks if this is of interest. (Just departing on vacation.)
My plan for packaging is to put a ZIP archive of the Python code in /assets and have the app unzip during the first onCreate. I haven't implemented this yet, but I don't expect any problems.

Is it possible to use Android scripts created with ASE as typical application for Android (e.g. written in Java)?

I am very very new to Android. I was encouraged to take a closer look at Android when I heard about possbility to write applications on Android in scripting languages like Python. This sounds great and in fact works great.
I did some experiments and everything looks very interesting. I have noticed that I can either write my scripts on Android or create script file on my computer and then copy them to Android ase/scripts folder. This is somehow different (as far as I know) from process of creating application for Android in Java (when you create code, compile it to .apk and install on Android).
To be more specific I want to know:
what are limitations (if any) of script-based applications on Android?
is it possible to ship apps written in scripitng languages to Android Market and let other users install them without requirement to install ASE?
is there some way to create more complicated, multi-file projects in scripting languages on Android?
Thanks for any hints. Also please feel free to correct me if I made any error or wrong assumption in my question - as I wrote, I am very new to Android.
what are limitations (if any) of
script-based applications on Android?
I would flip the question around. Scripts can only execute what is native to their language plus the things exposed by the Android facade. As such, you are not creating full user interfaces and the like -- at most, you have access to some pre-packaged dialogs (e.g., getPassword()). So, for scripting purposes, ASE is very slick, but you are not creating applications, IMHO.
is it possible to ship apps written in
scripitng languages to Android Market
and let other users install them
without requirement to install ASE?
Not presently. It is something that is being worked on.
is there some way to create more
complicated, multi-file projects in
scripting languages on Android?
Ummmm...you could try whatever sort of "include" construct there is in your language of choice.
Although I have not personally done so, it appears possible to compile your python scripts into an .apk. Take a peek at the instructions for sharing scripts on the [Android-Scripting Wiki][1]
[1]: http://code.google.com/p/android-scripting/wiki/SharingScripts"Android Scripting Wiki"

Categories

Resources