# Android/Developing on Android

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.
However, there are several ways of writing and editing software directly on the Android device. 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

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

### Bash script Hello World

Here is a quick "Hello World":
Install Termux by the method you prefer.
Tap the "Termux" icon.
At the command prompt,
type
(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:
Then press the Ctrl + X, "y" and Enter to save the program and quit back to the command prompt.
Execute the script:
You should see the output saying "Hello, world.".

## Terminal IDE
### Basic system setup

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
['' 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

You can ssh from your Android device in Termux into your favorite servers. Type your username, at-sign, and domain name like so:
The first time you connect from a particular Android device to a particular server, you will see something like:
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
until you go back to the Android device and type the command directly from the Android device's keyboard.

## Synchronization

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.

## Further reading

    (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.)
* The Terminal-IDE Organization
* "cloning from GitHub on Android using Terminal IDE"
* "Getting git Working on Android Devices" (Using Terminal IDE)
* "SSH and GIT on Android with Terminal IDE"
* ↑ Marc Hesenius, Carlos Dario Orozco Medina, Dominikus Herzberg. "Touching Factor: Software Development on Tablets". 2012. doi: 10.1007/978-3-642-30564-1_10 .
* ↑ Brian Kracoff. "15 Apps for Programming on Android". 2012. Mentions "Terminal IDE" from Spartacus Rex, "AIDE", "C4droid", "Pocket Code for Android", "Algoid", etc.
* ↑ Eric Ravenscraft. "AIDE Is An IDE That Lets You Write And Compile Android Apps On Your Android Device".
* ↑ "Termux". Termux. Retrieved 2024-05-12.
* ↑ 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.
* 1 2 Jason York. "Using Public Keys With Dropbear SSH Client". quote: "Now that ssh works, I can easily perform an automated rsync".