Ubuntu on Windows: Install Java 8 and Android Studio 4 + NDK
In this chapter, it’s simple. You can learn how to install Java8 and Android Studio on Ubuntu. So you can test the mobile app locally or on a Virtual Host. Here is the menu:
👍1. Install Java 8
🖖🏻2. Install Android Studio
👀3. Add NDK r21!
👍1. Install Java 8
The Android Studio is using Java 8 as its entry-level programming language. So you shall install Java 8 in the Ubuntu, too.
Open the terminal,
homanadmin@LAPTOP-THUV2CQ5:~$ java -versionCommand 'java' not found, but can be installed with:sudo apt install default-jre # version 2:1.11-72, or
sudo apt install openjdk-11-jre-headless # version 11.0.7+10-3ubuntu1
sudo apt install openjdk-13-jre-headless # version 13.0.3+3-1ubuntu2
sudo apt install openjdk-14-jre-headless # version 14.0.1+7-1ubuntu1
sudo apt install openjdk-8-jre-headless # version 8u252-b09-1ubuntu1
None can be found. Let’s install it.
sudo apt-get install openjdk-8-jdk
After the installation, let’s check again.
homanadmin@LAPTOP-THUV2CQ5:~$ java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
Good, let’s find java where it is installed /usr/lib with find command:
find /usr/lib -path ‘*java’
$ find /usr/lib -path '*java'
/usr/lib/jvm/java-8-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
The JDK and JRE are found. Let’s set the environment.
$ cat >> /etc/environment <<EOL
> JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
> JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
> EOL
bash: /etc/environment: Permission denied
Failed! You need “sudo” to override the permission. At first, I copy those two lines to notepad. In X Server, I will use “nano” editor.
$ sudo nano /etc/environment
[sudo] password for homanadmin:
I paste back from the notepad. Ctrl+X and save it. Let’s check.
homanadmin@LAPTOP-THUV2CQ5:~$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
Java is ready.
🖖🏻2. Install Android Studio
In the beginning, we need to check which version of Android Studio we shall install, 64bit or 32bit.
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
...
Obviously, it’s 64 bit. Now, let’s download the file from Android Developer site.
https://developer.android.com/studio
After you download the file, you will found it in your Download folder.
Let’s extract the file in the Download folder.
All of the private applications will go to /usr/local folder.
Right-click and open the terminal.
Let’s move the unzipped folder to /usr/local.
sudo mv android-studio /usr/local
Let’s check.
~/Downloads$ cd /usr/local
/usr/local$ ll
total 48
drwxr-xr-x 12 root root 4096 Jun 23 11:04 ./
drwxr-xr-x 14 root root 4096 Apr 22 23:41 ../
drwxrwxr-x 7 homanadmin homanadmin 4096 May 20 09:36 android-studio/
...
/usr/local$
Create Launcher…
Now, let’s add the shortcut on Desktop. In the bin folder of android-studio, the BASH file is studio.sh. This is your command.
And a PNG file is called studio.png, please insert it as an icon.
👀3. Add NDK r21!
The NDK can help us support the C++ code in Android Project. There are a lot of C++ files in Linux. So, let’s install the NDK!
Now, you can run the launcher to open a new “Empty Activity” project.
I’ll build a streaming app.
File->Project Structure…
-> SDK Location: Download Android NDK
After download, please “ndk-bundle” in the path option.