Jump to content

Android/Developing on Android

From Wikibooks, open books for an open world
(Redirected from Android/Terminal IDE)

The software for the vast majority of Android applications is written and edited on a laptop PC or desktop PC.

Some people think trying to write software directly on an Android device or other tablet is so different than writing it on a PC that it requires a new programming language supported by a completely new IDE.[1]

However, there are several ways of writing and editing software directly on the Android device.[2][3] Some of them takes a very traditional approach. It supports software development using a traditional command prompt; traditional text editors such as "vi"; the standard programming language for Android (Java); and the standard compiler for that language (gcc). The only thing non-traditional is that it runs them all directly on the Android device itself. (Even that can be seen as a return to a much older tradition of developing and compiling software on the same machine that runs the software).

Termux

[edit | edit source]

Termux is an open-source Android terminal emulator and Linux environment app that works directly with no rooting or setup required.[4]

Bash script Hello World

[edit | edit source]

Here is a quick "Hello World":

Install Termux by the method you prefer.

Tap the "Termux" icon.

At the command prompt,[5]

type

nano a.bash

(I'm assuming you've done a little programming before, so you'll know when to press the Enter button at the end of the line).

Enter a quick bash script:

#!/bin/bash
echo Hello, world

Then press the Ctrl + X, "y" and Enter to save the program and quit back to the command prompt.

Execute the script:

bash a.bash

You should see the output saying "Hello, world.".

Terminal IDE

[edit | edit source]

Basic system setup

[edit | edit source]

Follow all these tutorials through EXACTLY.

They will help you compile the sample applications in ~/system/src step by step.

The best way to follow these tutorials is by logging in over telnet/ssh and then you can read and follow on the device, whilst using the computer to perform the actions.

Let's Begin..

Installing the basic system.

Click 'Install System' on the main page, and then follow the instructions.

Make sure you have enabled the Terminal IDE Keyboard in Settings>Language and Keyboard on your device. Then choose the Terminal IDE keyboard - click 'Keyboard' on the main page.

Start Terminal IDE. Click the button..

You will now be presented with a nice not-short color prompt. You can change this by typing, export PS1=#

But it does look really nice over telnet/ssh.. :-p

  • Double-tap toggles the keyboard.
  • Swipe left and right to view your 4 Terminals.
  • Long pressing the screen brings up the Terminal Chooser menu.
  • Press 'Menu' for Options

[This part is optional but highly recommended]

Run telnetd. No parameters are required. Defaults setup in ~/.bashrc. You can see what is actually being run by typing: # cat `which telnetd`

(using backquotes, not apostrophes).

Anyway - start telnetd with: # telnetd

You should now see telnetd startup info. Ending in ../system/bin/bash

You can shut telnetd down at any stage by typing [CTRL]-C on the Terminal IDE Keyboard

Now, go to your nice big computer and login via telnet. I have set the escape character to blank, as it is the same as the vim help link follow key.

[Either] $ telnet -e [THE PHONES IP] 8080

[Or - better still with adb, which is part of the Android SDK] Plug your phone into computer via USB first. In you Android's developer options turn on Developer options and check USB debugging, then

$ adb -d forward tcp:8080 tcp:8080
$ telnet -e '' 127.0.0.1 8080

['' is 2 single quotes not a double quote]

Now you should be connected to the system via telnet

[And you can connect multiple times simultaneously]

OK - let's start programming.

Using Termux to ssh to a remote server

[edit | edit source]

You can ssh from your Android device in Termux into your favorite servers. Type your username, at-sign, and domain name like so:

ssh dc@dreamhost.com

The first time you connect from a particular Android device to a particular server, you will see something like:

   Host 'dreamhost.com' is not in the trusted hosts file.
   (fingerprint md5 c4:ad:7f:ba:d8:23:d4:da:53:07:76:a2:7e:24:9d:67)
   Do you want to continue connecting? (y/n)

So type "y" and hit Enter

You must do this directly on the Android device's keyboard the first time you connect to a particular server. If you are telnetted to your phone from some other machine, you will get the error

   ssh: connection to dc@dreamhost.com:22 exited: Didn't validate host key

until you go back to the Android device and type the command directly from the Android device's keyboard.

Synchronization

[edit | edit source]

The Terminal IDE includes "rsync", which is very useful for copying files, making backups, and quickly checking if files in two places are actually the same or not. [6]

Further reading

[edit | edit source]
(Later: add a few words about using dropbearkey to generate a local private key that never leaves the smartphone, and the corresponding public key ... so we never need to type in a password to securely log in to a remote server.)[6][7]
  1. Marc Hesenius, Carlos Dario Orozco Medina, Dominikus Herzberg. "Touching Factor: Software Development on Tablets". 2012. doi: 10.1007/978-3-642-30564-1_10 .
  2. Brian Kracoff. "15 Apps for Programming on Android". 2012. Mentions "Terminal IDE" from Spartacus Rex, "AIDE", "C4droid", "Pocket Code for Android", "Algoid", etc.
  3. Eric Ravenscraft. "AIDE Is An IDE That Lets You Write And Compile Android Apps On Your Android Device".[1]
  4. "Termux". Termux. Retrieved 2024-05-12.
  5. As you can check by typing echo $SHELL; the Spartacus Rex command prompt is a normal "bash" command line. See LPI Linux Certification/Work On The Command Line for a brief introduction.
  6. a b Jason York. "Using Public Keys With Dropbear SSH Client". quote: "Now that ssh works, I can easily perform an automated rsync".
  7. [2]