Android Development Environment

Setting up a Linux-based Development Environment on an Android Phone (Part 2)

Akinwunmi Oluwaseun
5 min readApr 1, 2018

This is the second part in the series.

After part 1, you should have a functional development environment on your Android device. This part is like a quick start manual for your development environment.

If you are already familiar with the Linux terminal commands, Tmux and Vim you can skip to Part 3 as a boss 🖖.

For those of us who are not quite bosses yet, here are some of the useful commands I’ve used while running my mobile development environment.

Linux Commands

cd: The change directory command is used to move between folders or directories using the directory’s path e.g.

# moves to the Document folder in the shared directory from
# checkout more information on '~' in linux symbols
cd ~/storage/shared/Documents

will move you to the Document folder in the shared directory in your HOME directory.

ls: The ls command lists the contents of a directory. You can also pass additional flags to show additional information about the files in the directory

# list the files and folders in the current directoryls# list all files in the storage directory including hidden files ls -la /storage

mkdir: mkdir is used for creating new directories in a specified path

# create a new directory called new in the current foldermkdir new
# create a new directory with the path
# create parent directories as needed
mkdir -pv new/path1/folder

rm: rm is used for removing (deleting) files and directories.

# delete textfile.txt from the current folderrm textfile.txt# delete folder directory in new/path1 folder
# -r flag removes folders recursively
rm -r new/path1/folder

cp: cp copies files from one directory to another. It takes two arguments; the source and the destination

# copy textfile.txt from current folder to new foldercp textfile.txt new/textfile.txt

mv: mv moves (cut and paste) files from one directory to another. It also takes two arguments like cp.

# move textfile.txt from current folder to new foldermv textfile.txt new/textfile.txt

find: The find command comes in handy when searching for files in a directory.

# look for all bash script (.sh) files in the current directoryfind . -name "*.sh"

chmod: chmod is used to change file permissions in Linux. The most common use is to make a file an executable, this is done using chmod’s +x flag.

# make startscript.sh an executable filechmod u+x startscript.sh

pkg and apt: Termux comes with two package managers; pkg and apt. Either of the two can be used for installing Linux packages and programs

# Search for the nodejs package in the package repositoryapt search nodejs
# Install the nodejs packageapt install nodejs

Linux symbols: In Linux and other UNIX terminals, you’ll come across some symbols with special meaning, these symbols make using the terminal easier. Some of the symbols you’ll come across include:

  • ~ : The tilde is a shortcut for your HOME folder. It can be used in defining paths in commands that take paths as argument.
  • - : When used as an argument to the cd command as in cd - You’ll be taken to your previous working directory
  • . : The dot “.” symbol is used as a shortcut for your present working directory
  • .. : Double dots are used as a shortcut for going one directory up the directory tree
  • | : The pipe symbol is used to connect two commands such that the output of one becomes the input of the other.
  • > and >> : The angle bracket (>) is used for redirecting output to a file and overwriting the file while the double angle bracket (>>) is used for appending output to a file.

Other tips:

  • Press tab once to auto-complete a command on the terminal.
  • Press tab twice to show suggestions for auto-completion.
  • Press Ctrl + R to autocomplete from your previously entered commands.
  • Press Ctrl + R repeatedly to go up your command history.
  • Ctrl + C is used for stopping programs in a safe way.
  • Ctrl + Z is used for force stopping programs

Getting Help with man and — help: Most of the commands you will use on the terminal come with a help utility that can be accessed by passing the — helpflag to the command e.g. ls --help.

Another way to get help is by passing the name of the command as an argument to the man command. man is a collection of manual pages for linux programs. To use man on termux you will have to install it first using pkg install man then open the man page of a command using man command e.g. man ls

VIM

I won’t be going over vim commands since vim comes with an awesome tutorial program called vimtutor. It covers all the commands you’ll need to get you started. Just take some time out to practice with the tutor and you’ll be up to speed in no time. To launch the VIM tutor program, run vimtutor in your terminal and follow the instructions in it.

Now that we know about the vim tutor, There’s a common gotcha faced by vim beginners… The legendary how do I close this stupid vim.

In case you’ve launched VIM already and don’t know how to close it, Don’t Panic, You’re not alone.

The first thing you should note is that vim is not stupid, it is a very powerful text editor that uses keyboard commands to increase your efficiency. It is one of the best text editors ever made (My opinion). To close vim all you have to do is enter the command:

:q!

and press enter or if you are in insert mode (You can type into the terminal in insert mode), Press escape first to go to normal mode, then enter the above command.

tmux

tmux or Terminal multiplexer is a program that allows you use multiple separate terminal sessions inside a single terminal window.

Being able to use multiple terminals in a single terminal window gives you lots of power and flexibility when using termux. You can use it to give your development environment an IDE feel and lots more.

Here are some of the tmux commands I use most often. Note that prefix refers to the keyboard shortcut for entering command mode, ctrl + b by default (You can change it later).

prefix + c: Create a new window

prefix + ,: rename a window

prefix + n or p: goto next or previous window

prefix + NUM key : goto window NUM

prefix + % : vertical pane split

Ctrl + d: close pane or window

These commands are just to get you started. For a more comprehensive list of commands you can check MohamedAlaa’s cheatsheet.

With these commands, you should be able to work productively with your development environment. In case you run into any further problems, don’t forget the internet is always there to help. Do a quick search on your favorite search engine and you’ll figure things out.

In the next part, we’ll go over optimisations to make your development environment truly awesome.

Ja ne!

Please don’t hesitate to give me a round of applause if you’ve found this post helpful by pressing the clap button a few times. It would mean a lot to me 😁.

--

--