Is Java or Python the Best Programming Language for Android Apps?

The following guest post comes courtesy of Michael Kordvani from fueled.nyc

***

Though Objective-C, Swift, Java, Python and HTML5 are widely regarded as the most popular mobile app programming languages, when it comes to programming languages for Android apps, it is Java and Python that are the rulers of them all.

But, perhaps you are an Android app developer who does not have a need for two programming languages. Perhaps, you just want the Big Dawg of all of the Android app programming languages in your toolbox. If so, read on to learn whether Python or Java is the best Android app programming language for you and your career.

Python

Python has been one of the most popular Android app programming languages for years because of these core tenets:

  • Readability Matters
  • Beautiful, not Ugly
  • Simple, not Complex
  • Complex, not Complicated
  • Explicit, not Implicit

So, really, when it comes time to learn how to create an Android app, Python deserves serious consideration.

Now, the majority of Android app developers do not learn this programming language because they are interested in Python’s core philosophy; they probably don’t even know about the philosophy. Android app developers choose the Python programming language because it is very simple to learn and features perhaps the easiest readability of all of the Android app developer languages in use today. One of the other main reasons for an Android app developer to code in Python is that the language supports dynamic typing, which can be a real game changer.

Now, you must not make the mistake of thinking that Python’s simplicity means that it cannot be used to create sophisticated apps. It can. In fact, Spotify, DropBox, Quora and YouTube were all developed on Python. That’s an amazing portfolio, yeah?

Java

Though Python has long been the one of the most popular app developing languages on the planet, it is not the most popular. Java is the most popular language.

Its popularity is one reason Android app developers ought to learn and work with it. After all, there is no other Android app programming language that has nearly as many open-source tools and Java-based libraries supporting it.

Another quality that Java is known for may be viewed by some developers as a negative. It is not concise. This is a great drawback for beginning Android app developers; however, skilled Android app developers tend to enjoy working with Java’s large vocabulary because it allows them to be as precise and creative as they could ever hope to be.

Java, Python: Which Should You Choose?

The bottom line is that only you can decide which Android app language is best for you and your career as an Android app developer. Novice developers tend to prefer Python for its simplicity, while experienced developers often choose Java for its extensive vocabulary. However, since there are currently close to 3 million Android apps available, you can rest assured that there is indeed a robust market for you and your apps, regardless of the language that may be the best fit for your project. Happy Android app building!

Advertisements

Installing Arch Linux (and R) on an Android device

This is a really recent development and I am very excited about this. I finally found a way to have a somewhat proper Linux installation on my phone. Though it might not be the best place to have a CLI, it is really promising and I can rely on this to do some small stuff on the go. As the tools I use are getting simpler (Photoshop vs Imagemagick) and the hardware of the phones I own are getting better, it is should possible for my phone to do the things my 5 year old laptop could handle provided the right environment.

This is done by installing a full Arch installation on an Android phone under the termux environment using the installer from TermuxArch. The installation here is actually way easier than installing Arch on a normal desktop. We start by installing termux android app. When we open termux we get a bash shell. From here we install wget by running, pkg install wget . When this is complete we download and run the Arch installation script by,

# Download the script
wget https://raw.githubusercontent.com/sdrausty/TermuxArch/master/setupTermuxArch.sh 
# Adding execute permissions
chmod a+x setupTermuxArch.sh
# Run the script
./setupTermuxArch.sh

Now we can just follow the instructions in the script which will download and unpack a base Arch Linux system and ask you to edit the mirror list. At this point, just  un-comment (remove the #) of the closest mirrors and save and exit the file. When the installation is complete you have a vanilla arch system on your mobile! Now we can theoretically install and use any program I have on my work desktop on my phone which including to ssh, vim, git, latex, R, node, postgres, mongodb, etc etc. I can even ssh into my work desktop straight from here. Below are some screenshots of the system (the chart is done entirely on phone!).

 

Clicker – A simple app to record pedestrian footfall precisely

I have finally published an app on the app store! It is called Clicker and it is a simple app I made for my research to count pedestrians on the sidewalk but it can be used to count incidence of any activity over time. The interface is as simple as it gets – open the app,  touch the screen to record any activity and the timestamp for every click is recorded (appended) in a csv file named with the current date in the folder “Manual Counts”. This file can be accessed by a file manager later and exported for analysis. A demo for the app is shown below,

update v2: With version 2 the data can be sent directly with any application (Gmail, WhatsApp etc) by long pressing the screen.

update v3: With the version 3 pedestrian walking direction can be differentiated by left and right buttons at the bottom of the screen.

The app is on google playGet it on Google Play

Minimal Android app development environment with MacOSX

I have always wanted to develop simple one page apps for android but have been put off by the whole IDE stuff (Eclipse/Android Studio). Personally, I like working with just command-line tools to make and compile programs the way I do for linux. Recently I came across a simple minimal app development environment at http://www.hanshq.net/command-line-android.html. which made me want to have a go at it. After a day of working on it, I put together a  barebones/ minimal environment for developing and building simple android app with just terminal in MacOS. As with everything I do lately, the text editing is done with vim and output is built with just command-line tools; no GUI, no fancy stuff.

First step is to get the software development kit (sdk) and the necessary development tools. This can be done in MacOSX using homebrew by,

brew install android-sdk
sdkmanager "platform-tools" "build-tools;27.0.3;" "platforms;android21"

We are going to use a example app called clicker which I made for my research to count pedestrians on sidewalk. It has a simple counter which can be increased by clicking anywhere on the screen. There are only three files which make the app, MainActivity.java which has the app logic, activity_main.xml which has the layout on the screen and AndroidManifest.xml which pulls the .java and .xml together to make the app. The folder structure is shown below and the sample files with the folder structure are attached here.

Screen Shot 2017-12-31 at 15.37.50

MainActivity.java

package com.bala.clicker;
import android.app.Activity;
import android.app.ActionBar;
import android.view.View;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ActionBar actionBar = getActionBar();
        actionBar.hide();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView text = (TextView)findViewById(R.id.my_text);
        text.setText("0");
        LinearLayout layout = (LinearLayout)findViewById(R.id.lay);
        layout.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                TextView text = (TextView)findViewById(R.id.my_text);
                int count = Integer.parseInt(text.getText().toString());
                text.setText(Integer.toString(count+1));
            }
        });
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:id="@+id/lay">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/my_text"
        android:textSize="65dp"
        android:gravity="center"
/>
</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bala.clicker"
versionCode="1"
versionName="0.1">
    <uses-sdk android:minSdkVersion="21"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application android:label="Clicker">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Before we can build the app, we need to make the required directories for the temporary files generated in the process. we do that by, mkdir -p build/gen build/obj build/apk. We also need a signature to sign the final app with before it can be installed on a device. This is generated by the keytool, keytool -genkeypair -keystore keystore.jks -alias androidkey -validity 10000 -keyalg RSA -keysize 2048 -storepass android -keypass androidFinally, for creating the building script we need to know the location of the android-sdk. this can be done by find command looking for “build-tools” as shown below sudo find / -name “build-tools”. This path (“/usr/local/Caskroom/android-sdk/3859397”) is defined as SDK in our script and used in our build script below. This is kept as build.sh in the root directory,

#!/bin/bash
# Defining the environment variables
SDK=/usr/local/Caskroom/android-sdk/3859397
BUILD_TOOLS="${SDK}/build-tools/27.0.3"
PLATFORM="${SDK}/platforms/android-21"
# Building the packages
"${BUILD_TOOLS}/aapt" package -f -m -J build/gen/ -S res -M AndroidManifest.xml -I "${PLATFORM}/android.jar"
javac -source 1.7 -target 1.7 -bootclasspath "${JAVA_HOME}/jre/lib/rt.jar" -classpath "${PLATFORM}/android.jar" -d build/obj build/gen/com/bala/clicker/R.java java/com/bala/clicker/MainActivity.java
"${BUILD_TOOLS}/dx" --dex --output=build/apk/classes.dex build/obj/
"${BUILD_TOOLS}/aapt" package -f -M AndroidManifest.xml -S res/ -I "${PLATFORM}/android.jar" -F build/clicker.unsigned.apk build/apk/
"${BUILD_TOOLS}/zipalign" -f -p 4 build/clicker.unsigned.apk build/clicker.aligned.apk
"${BUILD_TOOLS}/apksigner" sign --ks keystore.jks --ks-key-alias androidkey --ks-pass pass:android --key-pass pass:android --out build/clicker.apk build/clicker.aligned.apk
# Sending the apk to phone and starting the app.
"${SDK}/platform-tools/adb" install -r "build/clicker.apk"
"${SDK}/platform-tools/adb" shell am start -n com.bala.clicker/.MainActivity

finally we give execute privileges on the file to ourselves by chmod u+x build.sh”, connect the phone to the Mac via usb and run the script by “./build.sh”. Thats it! the app should be now installed on the phone and started as shown below,

app