Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to install the JDK on an android device?

Tags:

java

android

I want to be able to compile and run basic java apps within the android terminal termux. I checked out Terminal IDE, but that is incompatible with Android 5.0+. Additionally, I tried to install the arm64 jdk from Oracle's website, which android fails to recognize. I am running CM 13 and to clarify, I want to be able to run commands like javac and java directly from my phone.

like image 414
moderatelygood Avatar asked Apr 11 '16 03:04

moderatelygood


2 Answers

If you have Termux, you can download the deb file here, and install it with apt-get install /path/to/deb. A command to download and install the JRE and JDK for arm:

cd ~ # Change to home directory
apt-get install -y wget # BusyBox wget doesn't support HTTPS
hash -d wget # Forgets the BusyBox wget path so new one is used
wget https://archive.org/download/openjdk-9-jre-headless_9.2017.8.20-1_x86_64/openjdk-9-jre-headless_9.2017.8.20-1_arm.deb # Download JRE
wget https://archive.org/download/openjdk-9-jre-headless_9.2017.8.20-1_x86_64/openjdk-9-jdk-headless_9.2017.8.20-1_arm.deb # Download JDK
apt-get install -y ./openjdk-9-jre-headless_9.2017.8.20-1_arm.deb ./openjdk-9-jdk-headless_9.2017.8.20-1_arm.deb # Install the files
rm openjdk-9-*.deb # Remove the files after because they're huge

Or a one-liner to copy and paste:

cd ~ && apt-get install -y wget && hash -d wget && wget https://archive.org/download/openjdk-9-jre-headless_9.2017.8.20-1_x86_64/openjdk-9-jre-headless_9.2017.8.20-1_arm.deb && wget https://archive.org/download/openjdk-9-jre-headless_9.2017.8.20-1_x86_64/openjdk-9-jdk-headless_9.2017.8.20-1_arm.deb && apt-get install -y ./openjdk-9-jre-headless_9.2017.8.20-1_arm.deb ./openjdk-9-jdk-headless_9.2017.8.20-1_arm.deb && rm openjdk-9-*.deb

To install for another architecture, replace occurences of "arm" with the correct architecture. There are files for "arm" (most 32-bit phones), "aarch64" (ARM64/armv8, most 64-bit phones), "i686" (x86), and "x86_64". Most phones have either arm or aarch64. I believe the arm version should at least work on aarch64 (may be wrong?), so arm should work for almost everyone. But if you know what your device has, use that instead.

Edit: to find your device's architecture, run uname -m from Termux.

like image 119
beewall Avatar answered Sep 19 '22 15:09

beewall


@moderatelygood Go to Google Play Store and download GNURoot Debian. It is a fakeroot, i.e. terminal emulator. Many other terminal emulators are available in the Play Sore, but this ine is very good. It lives at https://github.com/corbinlc/GNURootDebian and website is http://corbinlc.github.io/GNURootDebian You can download many packages like this:

apt-get update

apt-get install default-jdk

apt-get install python

and so on.

You would be able to compile/run programs in these languages. Use some text editor to write programs, like Jota Text Editor, also available in Play Store.

like image 40
rps Avatar answered Sep 21 '22 15:09

rps