Java Or Python For Android – Why Not Both! – iProgrammer

Should you choose Java or Python for your next Android project? You don't have to with Chaquopy, the Python SDK that lets you write Android applications in Python. Thanks to support from Anaconda, it is now both free and open-source.

Chaquopy is versatile. It allows you to write Android applications in full in Python or partially, together with Java. You can pick the most suitable tool for the part of the application at hand.

Each approach has its own distinct advantages. If you have server backend that is written in Python you can now use Python for the front end as well without paying the penalty of context switching to another tool or language, or in lacking expertise in another stack.The extra boon is that you can use your favorite Machine Learning Python libraries like SciPy, OpenCV or TensorFlow solely on your client/mobile phone without connecting to the cloud.

While the cloud still monopolizes the space where neural networks and their algorithms breed, things seem to be shifting with those elaborate algorithms looking to move on to and run offline on mobile devices. That includes their training too; the pictures, notes, data and metadata that reside in the device will also serve to train the network and aid its learning activities such as the recognizing, ranking and classifying of objects.

The difference is that now all of that is going to happen locally. As such, common deep learning user experiences that could be realized locally, would be scene detection, text recognition, object tracking and avoidance, gesturing, face recognition and natural language processing.

For instance, apps that help in organizing photos on the user's phone, utilizing an algorithm that combines artistic photography principles with deep learning technology which can sort photos based on topics, locations, and events , and can also recognize the best, based on ranking system it employees.

Working offline and shifting business from the cloud and onto the device, has distinct advantages .Online processing requires the presence of either a WiFi or mobile connection which can be sluggish as well a host of privacy concerns. Then looking at it from an ever practical perspective, multiple concurrent requests from thousands of client devices can easily overload the cloud based service and leave the client machine prone to long delays in getting a response, or even to fully scaled denials of service.

So imagine having Python's ML libraries at your disposal on Android. This is happening thanks to Chaquopy. This goes beyond Python however;Java enthusiasts rejoice since Chaquopy through its APIs allows them to access those libraries from their Java code.

Don't get me wrong, I'm not taking away Chaquopy's other charismas like that of building UIs, accessing native Android APIs or working in sync with Java; it's just that having access to Python's ML ecosystem in a mobile device stands out.

Chaquopy is distributed as a plug-in for Androids Gradle-based build system, and you can access all native APIs and even build your app entirely in Android Studio. Also through simple APIs you can call Python code from Java and Kotlin, and vice versa. It can be used in any app which meets the following requirements:

In your projects top-level build.gradle file, the Android Gradle plugin version should be between 4.1 and 7.2. Older versions as far back as 2.2 are supported by older versions of Chaquopy.

The Android plugin may be listed as com.android.application, com.android.library or com.android.tools.build:gradle.

minSdkVersion must be at least 16. Older versions as far back as 15 are supported by older versions of Chaquopy.

Chaquopy's previous licensed locked down versions would work as advertised but only for five minutes of runtime. Open source projects were given a free license but commercial ones had to get a paid license. Not anymore. Thanks to support from Anaconda, Chaquopy is now free and open-source, with its SDKs full source code available on GitHub under the MIT license.The first open-source version is 12.0.1, released late July which apart from removing the license restrictions, is identical to version 12.0.0.

For examples of how to use Chaquopy, see the following apps:

That being said,Beewareis the closest to rival in that it allows using Python for cross-platform development.This means that you can have a single user interface across Android,IOs,Windows and Mac, thus with Beeware your app will have a standard look across all supported platforms while with Chaquopy you'll have just that native Android app experience.

But Chaquopy's strongest selling points are the deep integration with Android's development tools and its larger support for third party Python libraries. As noted in BeeWare'smanualitself support for third party Python libraries is limited:

On desktop platforms (macOS, Windows, Linux), any pip-installable can be added to your requirements. On mobile platforms, your options are a little more limited - you can only use pure Python packages i.e., packages that do not contain a binary module.

This means that libraries like numpy, scikit-learn, or cryptography can be used in a desktop app, but not a mobile app. This is primarily because mobile apps require binary modules that are compiled for multiple platforms, which is difficult to set up.

Its possible to build a mobile Python app that uses binary modules, but its not easy to set up well outside the scope of an introductory tutorial like this one. This is an area that wed like to address - but its not a simple task. If youd like to see this added to BeeWare, please consider supporting the project by becoming a member.

Chaquopy on the other hand has got that elusive support. Looking at itsnative package repositorywe find that amongst others it has support for matplotlib, numpy, opencv, pandas,scikit-learn,scipy and tensorflow. As well as the packages listed here, Chaquopy also supports most pure-Python packages on PyPI.

Ultimately Chaquopy gives you options. Go full stack Python. Keep the user interface in Java and connect to Python on the server or to Python's libraries on device. Access Java libraries from Python and vice versa. Keep the Java and Kotlin bits focused on the Android part and keep the Python bits focused on what Python does best.

ChaquopyChaquopy on GitHub

Fast.ai's Practical Deep Learning for Coders Has Been Updated

Knock Yourself Out With 91 Python Videos

To be informed about new articles on IProgrammer,sign up for ourweekly newsletter,subscribe to theRSSfeedandfollow us on Twitter,Facebook orLinkedin.

Make a Comment or View Existing Comments Using Disqus

or email your comment to: comments@i-programmer.info

Read the rest here:
Java Or Python For Android - Why Not Both! - iProgrammer

Related Posts
This entry was posted in $1$s. Bookmark the permalink.