Skip to content
This repository has been archived by the owner. It is now read-only.

Android

Buck Evan edited this page Mar 20, 2018 · 14 revisions

Using brew under Termux

NOTE: This is a work in progress! (March 2018)

This page is intended to get Homebrew into a working state on your Android device, via Termux.

Setup

Install Termux. Open the app and you should have a bash prompt.

Install homebrew prerequisites:

pkg update
pkg install git ruby curl clang proot make

Get a copy of linuxbrew:

git clone https://github.com/Linuxbrew/brew.git ~/prefix/brew
cd ~/prefix/brew
alias brew="termux-chroot $PWD/bin/brew"

Environment

These commands are needed to work around various issues and incompatibilities. You may want to put the environment variables in ~/.profile.

export HOMEBREW_TEMP=/data/data/com.termux/files/usr/tmp
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_ENV_FILTERING=1
export HOMEBREW_VERBOSE=1
export PATH="/data/data/com.termux/files/home/prefix/brew/bin:$PATH"

ln -s $PREFIX/bin/applets/* $PREFIX/bin  # This gives four "file exists" warnings. No worries!
ln -s $PREFIX/lib $PREFIX/include .

# Unfortunately you'll need to remember to re-do this whenever you install system packages.
ln -s $PREFIX/bin/* ./bin/

Use homebrew!

Let's check out the diagnostic tool: (you'll have to ignore these warnings)

brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Setting LD_* vars can break dynamic linking.
Set variables:
  LD_LIBRARY_PATH: /data/data/com.termux/files/usr/lib
  LD_PRELOAD: /data/data/com.termux/files/usr/lib/libtermux-exec.so

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
  /data/data/com.termux/files/usr/bin/apt-config
brew install hello  # currently, segfaults bizarrely during configure

Termux Tips

Chromebooks

To set up Android from a chromebook, use this guide: https://support.google.com/chromebook/answer/7021273?hl=en

If you want to connect via ssh, install Secure Shell and SSH Agent.

Linux

To run Android on top of Linux (or Windows or OSX, presumably), install Android Studio. The android virtual machines are called "AVD". Select tools -> AVD manager, and create an AVD with google play support. Press play, and you're off to the races.

Copy-Paste

You'll find ctrl-v doesn't work. Long-click the screen to copy or paste.

Ctrl-c

If you're having trouble sending special keys, there's a hidden utility in termux to help. Swipe from the left to reveal a menu, then long-press "keyboard" to expose a tray of special keys. You can now touch "CTRL" then "c" to send ctrl-c.

SSH

You'll get a better terminal and have an easier time with ssh keys if you run an ssh server in termux then use ssh to log in. Use this guide to set up SSH keys and ssh-agent. Check your setup by running ssh-add -L, which should print out your public key.

In Termux put your public key under ~/.ssh/authorized_keys. I was able to copy-paste, like so:

$ cat > ~/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+3GADn1Ihub9LciuSDpBqLnEE8vgS0H0/cBmTPswzZH9b1qVxpIZLQ3a2+st2qSZxMKOtj4jaxb2ppiKzN5cLT1ZBUrARJOt9wYv1qk8gIY4MhjDhBF40kihZqeGCuee5iPRt+lqQFnvdxoUIQVYqEXVw9/+QvFcTZiNq2SugqUASN8iVmIUHEWMIVHa+GK+E7Uh+gXR1DvDdr6THnUWGRcV+4Z07lSI4a09Ym5726US5lvpvSjYf3lxM5wd/86Y0qINvOze57GMGrYswcZkvd9IP70a8nyRwONVM/V6aW4OGS2rS5sRREBHGIcCdmD/QgU0O1tXMNyN1tO3zmVsv /home/buck/.ssh/id_rsa
EOF

Get your termux IP, termux user name (something like u0_a80), start the ssh server, and watch the server's logs:

pkg install openssh
ip -4 addr show scope global
id -un
sshd
logcat -s syslog

You can now ssh from your local machine to Android. The -A option forwards your ssh-agent identity to Android, which is very handy when authenticating with GitHub. (If you're using the Android Emulator, you will need to run <SDK>/platform-tools/adb forward tcp:8022 tcp:8022 first, and use "localhost" as the IP.)

ssh -Ap 8022 u0_a80@<IP>

Project History

There was a good amount of discussion within Linuxbrew issues https://github.com/Linuxbrew/brew/issues/598 and https://github.com/Linuxbrew/brew/pull/621.

A log of previous (fixed?) issues is here: https://docs.google.com/document/d/1FNMnPTKIrXkloFFoHtTXZl2yAgvXm4G-0hHAd0RbLVY/edit#heading=h.mkvoio42su01

You can’t perform that action at this time.