There are some cool python scripts out there and I was wondering what is involved in running one within an Android device? Is this possible? I don't want to call out to a server. Thanks
It is possible, although with limitations.
The Scripting Layer for Android provides and interface for script languages to expose a great deal of Android's internals.
You will need a specific built of python though, that you can get here.
Some libraries are also being simplified and shrunk to be available on Android. For example pyGame (pretty much the standard for 2D games on python) has recently released this.
Take a look at SL4A.
Related
I am currently planning the development of a multiplatform app, and I am not sure wich way to do it fits my requirements best, since all possibilties I could think of failed to satisfy me.
First I want to write an app for android, which should feel like a normal typical android app. So I want to use the standard actionbar and android design look and feel in my other gui elements. After finishing the android app I am planning on developing an ios app, which should have a different design, so i am going to redevelop the gui for this anyway.
But I don´t want to rewrite the other code wich represents the intelligence of the app, independent from the gui. I came up with the following possibilities:
1. Java GUI With native library
Here I abstract all the code of my app in a C++ library (since as far as I know ios supports the usage of c++ libraries too) and develop the gui android typically in java. The library would than have a function to start and would inform the gui about every change via callback functions.
Pro
I can reuse all the code that would be the same on both platforms. I just would implement the gui seperately
The design of the android gui is straightforward as I want it to be. It looks like typical android because it is typical android.
Cons
I dislike the usage of JNI very much. Especially the signature and names of the callback functions (calling java functions from c++) are not checked at compile time and require a lot of manual work. If I rename a function and forget to rework the native part I only notice this mistake at runtime.
2. Build the GUI on the native side
Here I had difficulties finding out what is possible, especially for 2.2
2.1 Use Qt
I have only a few first step experiences with Qt in general but as far as I understood i would have the following pros and cons:
Pro
Reuse most parts of the code for ios and Android. I would than redesign the gui for each platform to make them feel natural. I can´t evaluate how much qt may even assists me at doing that
Cons
I have to copy the android gui by using other qt widgets. This is more effort and I don´t know if one can replicate the android gui elements (like the actionbar) so that the user wouldn´t notice it.
2.2 Using the android framework from the native side
I dont know if this is possible at all, I wasn´t able to find this information. Can I use the class "NativeActivity" and use the android framework to build the gui and use e.g. the actionbar? If this is possible somehow it would have the pros from 1. and maybe wouldn´t have it cons?
Do you have any feedback to my ideas or maybe even new approaches I didn´t think of? How do other multiplatform apps like WhatsApp solve this problem? Do they have redundant code for each platform?
Thank you,
Tobi
I would say that it depends very much on your application requirements. By my opinion, a better solution is to develop a separate application for each platform using recommended SDK's for that platform, and implement in native C++ only the time consuming data processing algorithms.
Application runtime on mobile platforms is not so straightforward as on desktop platforms. You should take into account background and foreground processing, specific application life cycling, accessing system resources such as network, file system, etc. And all these issues do differ on iOS and Android.
Regarding possibilities that you listed.
Qt/QML is ok only in case two requirements are met:
1.1 Your application is a foregroud application without any background operations.
1.2 You purchase a commercial Qt license because only commercial Qt can be submitted to Apple iTunes app store (even GPL apps are under
question).
Using NDK Native Activities on Android with cross-platform C/C++ backend. Android NDK API offers much less API then Android Java SDK, so a lot of things you will have to implement or wrap manually. It is a hard road.
Mixing Java code and C/C++ using JNI gives you more of Android SDK API. But you should remember that an Android activity's life cycle is not somewhat that you're used to deal with when developing on C/C++.
Approach that we are using
We've been developing an application with a huge amount of cross platform functionality that should work on Windows/Linux/Mac OSx/Android/iOS. We're using the approach as follows.
Cross-platform core is written in pure C++.
We have adaptors to GUI interface for each platform.
On desktop we use Qt as it reaches all desktop platforms with minor adapting to each platform.
On iOS the GUI is built using iOS SDK with Objective-C and C++ core is linked as a Framework. Still, we had to patch our core in some way for iOS background requirements and so.
On Android we wrap our C++ core in a background process and build all the GUI using only Android Java SDK. Foreground GUI activities interact with the core via local sockets, so we don't need to bother with activities life cycling in our C++ core. But the adaptor is a litle bit complicated.
Nevertheless, both mobile platforms often require workarounds and adaptations in C++ core which add a number of #ifdef'ed branches in code for each platform.
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
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.
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.
I've been searching solutions for my enterprise apps, at least 3 platforms need to be supported, which are iOS, Android and Window Phone. After a whole day's search, I finally set my eyes on 2 promising cross platform solutions, one is monocross and the other phonegap.
monocross seems to use c# and .net at all, is it possible to access native libraries and languages? I read somewhere it's compiled directly into binaries that can execute on target platforms.
And about phonegap, it uses webviews on each platform to provide the capabilities of presenting user interfaces to final users. As it's implemented via interpreted language and high level apis, the performance may not meet our needs.
Finally, we(my team) decide to give it a try with mono, the architecture is illustrated as bellow:
+++++++++++++++++++++representation layer++++++++++++++++++++++++++
[monotouch,monodroid,silverlight]or [native gui calls] or [html5/js/css]
+++++++++++++representation controller/business logic layer+++++++++++++++
[ mono/c# ]
++++++++++++++++++++++++++++server side+++++++++++++++++++++++++++
[ the cloud ]
I want to use mono/c# to write some common purpose business logic and data structures, and when it comes to some common platform features, like storage service, notifications, I'd like to wrap them up on each platform and expose uniform apis for c#(business logic layer) to use. As to the representation layer, we decide to choose from the 3 optional solutions listed above.
To make this happening, first I have to figure out if it is possible to call native frameworks.
So, my questions are:
1, How does mono work, I mean, are the c# codes compiled into binaries that can be executed directly on iOS, Android and Windows Phone?
2, Is there a mechanism to make native invocations? Like in cocos2d-x, I can call java methods via JNI, and in iOS, c++ can call oc directly. Can I call cocoa touch stuffs in mono with c#?
3, Is it possible to manage all these stuffs in one single project, and how to build them?
4, Are there any better solutions?
Any suggestions will be appreciated, thanks for your patience!
I wonder why Xamarin does not land on the first page of your search result,
http://xamarin.com/features
But that's what the Mono guys created for the C# developers that want to target mobile platforms. MonoTouch and Mono for Android are there each featuring a common library base with Microsoft .NET, and also platform specific bindings.
Your non-UI code should be able to be used in portable libraries and share among them. Microsoft's portable library is Windows specific, and right now I am not sure how much Mono guys can embrace that, but even if PCL fails, you can create multiple platform specific projects based on the same copy of source files (which I did in #SNMP). The remaining task is to develop platform specific UI for Windows Phone, iOS, and Android.
There are tons of articles showing the features,
http://docs.xamarin.com/
and also many successful apps
http://xamarin.com/apps
The best way to learn a product is to try it out (for free in Xamarin's case). This also applies to MonoCross (which is a framework built upon Mono).
I am not familiar with PhoneGap, so you need someone's advice on that.
Disclaimer: this is not a complete answer - but I do hope it answers at least part of your question
I encountered a similar problem when I started cross-platform dev using the Mono products 18 months ago.
The approach I've built since is called MvvmCross - it forked off of MonoCross a long time ago - now shares no code with it (but maybe we'll team up again one day!).
The approach uses PCLs to share code. This is not entirely painless, but is easy after you've done a few setup steps - http://slodge.blogspot.co.uk/2012/12/cross-platform-winrt-monodroid.html
You can learn more about this approach on this video: http://slodge.blogspot.co.uk/2012/12/mvvmcross-video-presentation-xaminar.html