Friday, November 18, 2016

How to Install Oracle Java 8u111 and Android Studio 2.2 on a 64-Bit Linux Mint Debian Edition 2 MATE (Betsy)

NOTE: This article updates the previous one on Java and Android Studio on a 64-bit Linux Mint Debian Edition 2 (Betsy). Oracle's Java is now at version 111 and Google's Android Studio is now at version 2.2.2.

This article is a ‘how-to’ for installing Oracle’s Java JDK 8u111 (or SE 8u111) and Google's Android Studio 2.2 on a 64-bit Linux Mint Debian Edition 2 (LMDE2), code-named Betsy, PC. If you wish to develop software on the Android platform on your LMDE2 PC, then this ‘how-to’ is for you. Note that most necessary steps are performed at the command line in a terminal – if you are not familiar with this, I suggest reading about it first before trying out this ‘how-to’.

Before we start off on our journey, I will assume that you have installed the latest version of LMDE2 and apply all the latest updates for the PC. Also note that I will assume that you have installed the proper propriety video drivers on your PC. Note that this article is based on a Nvidia GeForce video card equipped PC, with the propriety video driver installed. AMD video card, with the propriety video driver installed, will cause problems with Android Studio, especially when trying to run an emulated AVD. This issue (along with the error messages) will be pointed out later in this article.

This article was tested on the following hardware and found to be working:
  • Gigabyte GA-Z97-HD3 Motherboard
  • Intel Core i5-4590 CPU (3.3 Ghz)
  • Kingston 16 Gb DDR3 HyperX RAM
  • Nvidia GeForce GTX-750Ti PCIE Graphics Card
Note that, although this article is written for the MATE desktop, with a little bit of tweaking, it can work for the Cinnamon desktop too.

STEP 1: Remove OpenJDK JRE’s From LMDE2

On a newly-installed and updated LMDE2, only OpenJDK JRE (Java Runtime Environment) 7 is installed by default. Google’s Android Studio, however, requires the full Java JDK, and the recommended version is Oracle’s Java (JDK or SE 7 and above). So, the first thing to do is to delete the OpenJDK 7 JRE and install Oracle's Java JDK 8 in it's place.

Before we delete OpenJDK JRE from the PC, we have to disable Libre Office from using Java. Click on ‘Menu’ > ‘Office’ > ‘Libre Office’. Libre Office will open. Click on ‘Tools’ > ‘Options...’. Click ‘Advanced’ and de-select ‘Use a Java runtime environment’ and click ‘OK’. Close Libre Office.

If you launch the Firefox browser now, and type ‘about:plugins’ in the location (URL) bar, it will show that ‘IcedTea-Web Plugin’ is one of the plug-ins installed. It will not be possible to remove this plugin using Firefox’s add-ons tool as this plug-in was installed by OpenJDK itself. So we have to turn to the Synaptic Packet Manager to do the job.

Make sure that Firefox is closed, then launch Synaptic and enter ‘icedtea’ into the search box (do not use the Quick Filter). Then mark the following items for complete removal:

  icedtea-7-plugin (+icedtea-plugin)
  openjdk-7-jre (+default-jre)
  openjdk-7-jre-headless (+ca-certificates-java, default-jre-headless)

(Note: those preceded by '+' are to be marked for removal also – these items will appear if the main item are selected for complete removal).

Click the ‘Apply’ button to remove the marked files, then close Synaptic. You can then check whether the Firefox Java plug-in has been removed by launching Firefox again and typing ‘about:plugins’ in the location (URL) bar. The resulting display should indicate that there is no Java plug-in present now. Then close Firefox again.

STEP 2: Install Oracle’s Java SE (or JDK) 8

Point your web browser to the Oracle SE download page here and download the latest version of the 64-bit JDK (not Server JRE or the JRE) – currently at version 8u111 (or 1.8.0_111).

NOTE: There are currently two versions of Oracle’s Java SE (or JDK) – versions 8u111 and 8u112. Please refer to the release notes of each version to determine which version is suitable for you. In the case of this article, version 8u111 is used as an example – you free free to choose which version to install.

It is also recommended that you download the API documents, demos and samples for the JDK – although this is not required for Android development on Android Studio. Once the packages have been downloaded, execute the following commands:

  cd Downloads
  tar xzvf jdk-8u111-linux-x64.tar.gz
  tar xzvf jdk-8u111-linux-x64-demos.tar.gz
  unzip -d jdk1.8.0_111

The last two commands in the above is only applicable if you have downloaded the demos and the documentation. The second command above will create a ‘jdk1.8.0_111’ directory in the Downloads folder while the last two commands above (if applicable) will create the ‘sample’, ‘demo’ and ‘docs’ directories under the ‘jdk1.8.0_111’ directory in the Downloads folder.

Now execute the following commands:

  sudo mkdir /usr/lib/jvm/
  sudo mv jdk1.8.0_111/ /usr/lib/jvm/
  cd ~

This will first create the ‘/usr/lib/jvm/’ directory then move the whole ‘jdk1.8.0_111’ directory to that directory – where the root of all Java-related files resides. The last command will place you back into your home directory.

Notice that the owner and group of the ‘jdk1.8.0_111’ directory is still in your name and group. You can keep it as it is if you are the only user of the PC or you can set this to root by executing:

  sudo chown -R root:root /usr/lib/jvm/jdk1.8.0_111

Note that, although you have installed Oracle’s Java, the system still does not know this. As a quick check, you can execute ‘sudo update-alternatives --display java’ in a terminal, and you will get an message that says ‘update-alternatives: error: no alternatives for java’ in return.

To fix this, you need to tell LMDE2 where Oracle’s Java JDK resides and set up a default Java. For this we use the ‘update-alternatives --install’ command. Execute the following command from the terminal (note that the command is on a single line):

  sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_111/bin/java" 1500 --slave "/usr/share/man/man1/java.1" "java.1" "/usr/lib/jvm/jdk1.8.0_111/man/man1/java.1"

These will install all the necessary links to Oracle’s Java, including a slave link for the ‘man’ pages for Java. After the command has been executed, the default Java is automatically set to Oracle’s Java.

To verify that all have been set correctly, you can use the following commands:

  update-alternatives --display java

If the output to the query above looks like the following, then everything have been set correctly:

  java - auto mode
    link currently points to /usr/lib/jvm/jdk1.8.0_111/bin/java
  /usr/lib/jvm/jdk1.8.0_111/bin/java - priority 1500
    slave java.1: /usr/lib/jvm/jdk1.8.0_111/man/man1/java.1
  Current 'best' version is '/usr/lib/jvm/jdk1.8.0_111/bin/java'.

A quick check on the current version of the Oracle’s Java can be performed by executing the following command in a terminal:

  java -version

If the output for the command looks like this, then Oracle JDK 8 has been set up properly:

  java version "1.8.0_111"
  Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
  Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

STEP 3: Set the System's Environment Variables and Paths

Now we have to set the environment variables and paths correctly for the whole LMDE2 system. Execute the following command:

  sudo nano /etc/profile

This will execute the nano text editor and open the ‘/etc/profile’ file for editing. Now add (or edit) the following lines at the end of the file.

  export STUDIO_JDK=/usr/lib/jvm/jdk1.8.0_111
  export JDK_HOME=/usr/lib/jvm/jdk1.8.0_111
  export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_111
  export PATH=$PATH:$JAVA_HOME/bin

Save the file and close it. Note that, upon system startup, these will set the STUDIO_JDK, JDK_HOME and JAVA_HOME and PATH environment variables for the whole system. The STUDIO_JDK, JDK_HOME and JAVA_HOME environment variable points to the JDK root while the PATH environment variable will add the ‘/bin’ directory of the JDK to whatever path that has already been specified. Note that these environment variables will be used for Android Studio, and other programs which uses Java. This also will enable the ‘javac’ (the Java compiler) command to be executed from any directory. Note that the ‘javac’ command is not essential to Android software development, but it could prove useful if you are running Java programs from a terminal. It also would be useful if you are new to Java and wish to test software from the command line during the learning process.

Now log out and then log in again to the system in order to make sure that both the environment variables are set. Check that you have correctly installed Oracle Java by executing the commands (one by one) in a terminal:

  echo $STUDIO_JDK
  echo $JDK_HOME
  echo $JAVA_HOME
  echo $PATH
  java -version
  javac -version

If you see the string ‘jdk1.8.0_111’ in the output to the above commands, then you have successfully removed OpenJDK 8 JRE and replaced it with Oracle’s SE 8.

Now whenever Oracle issue an updated version, all you have to do in order to use the new version of Java SE is to follow STEP 2 above and this step (STEP 3). Just make sure that you change the version number to the new version in the commands shown. However, you do not have to re-create the ‘/usr/lib/jvm’ directory as it already exist. Also make sure that you remove the links to the old version of Java by using the ‘sudo update-alternatives --remove-all java’ command before implementing the links to the new version of Java in STEP 2.

STEP 4: Install 32-Bit Libraries

Since you are using the 64-bit version of LMDE2, run the following commands in a terminal to download and install some necessary 32-bit libraries:

  sudo apt-get install lib32z1 lib32ncurses5 lib32stdc++6 lib32gcc1 lib32tinfo5 libc6-i386

Note that, if you fail to install these packages, you will not be able to use Android Studio without running into errors.

STEP 5: Install Google's Android Studio

Point your browser to here and click on the big green button and then agree to the terms. Click on the download button and wait for the download to finish.

NOTE: As of November 2016, the version of Android Studio stands at version 2.2. This version differs from any of the previous versions; so the user must take this into consideration – especially those users that are used to using the standalone SDK and AVD Managers. It must be pointed out to new users that the Android Studio is now based upon the Jetbrains’s Intellij IDE – which is vastly different from the Eclipse IDE on which the previous Android Studio is based. So new users are encouraged to read about the Intellij IDE before using it.

To install Android Studio, first start a terminal and then execute the following command:

  unzip Downloads/

Note that the version number in the file name may differ from the one shown above because Google issues new updates constantly. Always use the latest version although the screen shots in this article applies to the version shown above.

To start Android Studio setup, execute the following commands in a terminal, one by one:

  cd android-studio/bin

A window similar to the one shown below, will appear asking whether you would like to import any settings. If this is the first time you are using Android Studio, it will be likely that you don’t have anything to import. However, if you are moving from an older version of Android Studio, you may want to keep any settings made previously – in this case specify the location of the settings, and let the setup wizard do the job.

Click on the ‘OK’ button to proceed. Android Studio will begin loading as shown in the figure below.

After a while, the ‘Setup Wizard’ window similar to the one shown below, will appear. Click on the ‘Next’ button to continue.

The next window (‘Install Type’) similar to the one shown below, will appear. The Standard type of setup is already selected – this is recommended unless you want to customize the setup. Click on the ‘Next’ button, and the next window will appear.

The next window (see below) is the ‘Verify Settings’ window, where you will find settings like the setup type, the destination folder, and the SDK components to be downloaded next, plus the total size of the downloads. Click on the ‘Next’ button and the the next window will appear.

If you have Intel’s Virtualization Technology enabled in your PC BIOS and Linux kernel, then it will be detected as shown on the wizard’s window. You can read up more on this technology at the URL shown on the window. Then click on the ‘Finish’ button.

The SDK components mentioned in the ‘Verify Settings’ window will begin downloading as shown below. Wait for the download and installation of the SDK components to finish.

Once downloading and installation is completed, a log window will appear as shown. Note that this log window is where any error messages, if any, will be displayed. Assuming that the log window does not display any error messages, click on the ‘Finish’ button.

The next screen shown is the Android Studio Welcome Screen itself (shown below). You have now successfully installed Android Studio Version 2.2 on your LMDE2 PC.

NOTE: The latest version of Android Studio has a new look which differs from the previous version. One of the major difference is the way Android Studio handle updates – if there are any, a small window will pop up on the top right hand corner and informs you of the fact. Just click on the ‘update’ item and follow the on-screen instructions if you wish to apply the updates.

You can now pause and admire your handiwork, then close Android Studio by clicking on the ‘x’ on the top right hand corner of the window. Ignore any warnings on the terminal and then close it.

Remember that, at the moment, you have to start a terminal, change to the correct ‘/bin’ directory and then launch ‘’ in order to start Android Studio. Surely there must be an easier way and there is! To place a launcher icon on your desktop, follow the steps outlined below:
  1. Right-click on an empty portion of your desktop and select ‘Create a new launcher here...’
  2. A window similar to the one shown below, will appear. You an now enter a name for the item – ‘Android Studio’ seems appropriate here. Then for the command, click on the ‘Browse’ button and select the ‘’ file in your ‘~/android-studio/bin’ directory. In the comment field, enter any text you like – ‘Google's Programming IDE for Android’ seems appropriate here. Leave the ‘Launch in Terminal?’ field unchecked.
  3. For the icon, click on the placeholder icon, and navigate to your home directory, double-click on ‘android-studio’ and ‘bin’ directories and then select the ‘studio.png’ file (see figure below). Then click ‘OK’ to dismiss the ‘Launcher Properties’ window. A window may pop up asking you whether you want to create a menu item for Android Studio also (see below). Should you say ‘Yes’, that item will be placed in the ‘Other’ category.

The icon for the launcher should be on your desktop (see below). You can test the launcher by double-clicking on it – Android Studio should start up. Then close Android Studio again.

If you had created a menu item, you can also place an Android Studio icon in you LMDE2 panel. Click on the ‘Menu’ and then locate the Android Studio item under the ‘Other’ category in the menu. Right-click on this item and then select the ‘Add to panel’ item – then press the ‘Esc’ key to dismiss the menu. The Android Studio icon will appear in the panel – single click on this icon to start Android Studio.

If you want to launch Android Studio from anywhere using ‘’ on a command line, it is recommended that the system wide path include the ‘android-studio/bin’. To do this, execute this command in a terminal:

  sudo nano /etc/profile

In the ‘profile’ file make sure to include the ‘android-studio/bin’ in the PATH – for example:

  export PATH=$PATH:$HOME/android-studio/bin

If you have already implemented the path to JAVA_HOME (as in STEP 3), then the new line should look like this:

  export PATH=$PATH:$JAVA_HOME/bin:$HOME/android-studio/bin

Save the file and close nano. To make sure that this new path takes effect, log out and then log in again. Now you can launch ‘’ in a terminal from any directory.

STEP 6: Configure SDK Manager

Launch Android Studio again if you have not already done so. Notice the ‘Configure’ on the last line of the window. Click on it and then click on the ‘Project Defaults’ item, then click on the ‘Project Structure’ item (see below). The ‘Project Structure’ window similar to the one shown below will appear. Note that, by default, Android Studio will use the embedded JDK at the location stated. Since you have already installed Oracle’s JDK, we will now point to that new location, instead of using the embedded JDK. First clear the check mark for the ‘Use embedded JDK (recommended)’ item – then click on the ‘...’ button. Navigate to the ‘/usr/lib/jvm/jdk1.8.0_111’ directory, then click the ‘Apply’ button, followed by the ‘OK’ button. The final window will look like the one shown below. Then click on the ‘OK’ button to dismiss the ‘Project Structure’ window. You will be back at the Android Studio welcome screen.

At the Android Studio welcome screen, click on the ‘Configure’ again and then click on the ‘SDK Manager’ item (see below).

The ‘Default Settings’ window similar to the one shown below will appear. Note that the ‘Android SDK’ item in the left-side pane is already selected by default. Also note the ’Launch Standalone SDK Manager’ item – users of the old version of Android Studio will be familiar with this item, as this will launch the old standalone SDK Manager. Click on this item and the window shown below will appear – with the lower right button showing that there are n updates available (where n can be any number). If there are no updates (i.e., the ‘Install packages’ button will be grayed out), it will be safe to close the standalone SDK Manager and you will be back to the ‘Default Settings’ window.

If there are updates, as shown in the figure as an example, and you wish to apply them, click on ‘Install 3 packages...’ button. On the next window that appears, accept the license (see below), then click on the ‘Install’ button. The packages will then be downloaded and installed – after which the display will look like the one shown below. Then close the standalone SDK Manager using the ‘x’ on the top right hand of the window, and you will be back to the ‘Default Settings’ window.

NOTE: From now on, I suggest that you check if there are any updates by using the standalone SDK manager. This should be done every time you start Android Studio.

Close the ‘Default Settings’ window and you will be back at the Android Studio welcome screen. Then restart the ‘SDK Manager’ again in order to refresh it (a bug?). Now enable the item labeled ’Show Package Details’ – the display will change as shown below.

Now it's time to check what has been installed so far. On the right side pane of the window, all installed packages are marked ‘Installed’ under the ‘Status’ column. Note that Android SDK Platform 25 package has already been installed for Android 7.1.1 (Nougat) – the latest Android version from Google. Other packages may have already been installed – just check the ‘Status’ column.

Depending on what Android devices that you wish to develop software for, you may wish to install additional packages for that device. For example, the author has an Android Nexus 5X smart phone running Android version 7.0 (Nougat), so the packages marked as shown below, was selected to be installed. Take note that all versions of Android is backward-compatible (at least in theory) so it is safe to include the latest version as shown. Note that you are free to choose the packages to install – the screen shown includes all packages for Android 7.0 and 7.1.1 (Nougat). Then click on the ‘Apply’ button. A ‘Confirm Change’ window will pop-up next as shown below. Click on the ‘OK’ button. Then the ‘License Agreement’ window will appear as shown below. Accept the license and click on the ‘Next’ button.

The next window (‘Component Installer’) will appear as shown below. This will display the progress of the downloads as well as the installation of the packages. Wait until the downloads and installation has been completed – then click on the ‘Finish’ button (see below).

You will be back at the Android SDK window where all the installed packages will be shown under the ‘Status’ column (see below).

You can now explore the Android SDK – click on the ‘OK’ button when you are done, and you will be back at the Android Studio welcome screen.

STEP 7: Create a New Project Using Android Studio

Now that you have successfully installed Oracle’s Java SE 8u101 and Google’s Android Studio 2.2, it’s time to use Android Studio to develop software for the Android platform. We start off by using Android Studio to write a short and simple ‘Hello, world’ program, which you can run either on your AVD (Android Virtual Devices), or your actual Android device.

Launch Android Studio if it is closed, then start a new project by clicking on the ‘Start a new Android Studio project’ item from the welcome screen (see below).

The ‘New Project’ window as shown below will appear – fill in the details for the ‘Application name’ to ‘Hello World’, and ‘Company Domain’ to ‘’ as shown. Do not place a check mark in the ‘Include C++ Support’ box. The directory in which this project reside can be anywhere on your PC. In the example shown, I have placed the project in my home folder’s ‘Projects’ directory but you are free to use any directory you wish. Then click on the ‘Next’ button.

The ‘Target Android Devices’ window will appear next (see below). Make sure that the ‘Phone and Tablet’ item is selected. The ‘Minimum SDK’ is pre-selected to be ‘API 15: Android 4.0.3 (IceCreamSandwich)’ and the reason why is as stated in the note below this field. If you are unsure on which minimum SDK to select, you can click on the ‘Help me choose’ item. For this tutorial, leave it at the pre-selected minimum SDK. Then click on the ‘Next’ button.

The ‘Add an activity to Mobile’ window will appear next (see below). Select the ‘Empty Activity’ item if it is not pre-selected. Then click on the ‘Next’ button.

The ‘Customize the Activity’ window will appear next (see below). Change the ‘Activity Name’ to MyActivity and the rest of the items below will change as shown. Then click on the ‘Finish’ button.

Android Studio (the ‘Gradle’ part anyway) will then start building the project as shown below. Note that your project is a basic ‘Hello world’ app that contains some default lines so you do not have to enter those lines into the project. Later you can view the the Java source code for this ‘Hello world’ project in the Android Studio IDE.

When completed, Android Studio will display it’s main IDE screen. If a ‘Tip of the Day’ window appears (shown below), you can safely close it by clicking on the ‘Close’ button. You can also disable this window by clearing the check mark next to the ‘Show Tips on Startup’ item. If this is the first time you are using Android Studio, the next screen will take some time to appear while the system will carry out indexing of the IDE – the word ‘Indexing...’ will appear in the bottom of the IDE window (see below).

After the system has finished indexing, a screen similar to the one shown below will appear. Note that it shows the source for the package ‘MyActivity’ Java class. Click on the ‘activity_my.xml’ tab and the window as shown below will appear. Note that it does contain a graphic of a device with the ‘Hello world!’ text on it. This, however, is NOT the output of the project.

STEP 8: Create a New Emulated Android Device

Before we run this project in order to test it, we will require an Android device to run the project on. We can either run the project on a emulated Android device or an actual Android device. Running the same project on an actual Android device will be described later. We will now create an emulated Android device based on a Nexus 5X device. Why this Android device? The simple answer is ‘because the author has one’. You are free to create any Android device of your choosing – the procedure is the same for all Android device.

NOTE: There are two ways of creating an emulated Android device. One is via the old standalone SDK manager and the other is using the ‘Tools’ menu on the Android Studio (while a project is open) itself. This article will use the new way instead of the old standalone SDK manager.

Click on the ‘Tools’ menu, followed by ‘Android’ and finally ‘AVD Manager’. The ‘Your Virtual Devices’ window will appear (shown below). Click on the ‘Create Virtual Device...’ button. The ‘Select Hardware’ window will appear. Note that a Phone device labeled Nexus 5 is already pre-selected. Since this is NOT what we want, select the one labeled Nexus 5X (see below). Then click on the ‘Next’ button.

The ‘System Image’ screen will appear (shown below). The recommended one is already pre-selected but it’s not what we want – instead select the one labeled ‘Nougat 24 x86 Android 7.0 (with Google APIs)’, then just press the ‘Next’ button. A screen similar to the one shown below will appear – just press the ‘Finish’ button.

The AVD will be saved (see below) and the final screen listing your virtual devices will be displayed as shown. You can edit this AVD anytime by first selecting it and clicking on the edit icon (looks like a pencil) at the column marked ‘Actions’. Note that, besides editing this AVD, you can also run it (by clicking on the Run icon) and perform various functions by clicking on the down arrow icon.

To edit this AVD, click on the edit icon and the ‘Verify Configuration’ window as shown below will appear. You can make necessary changes here. You can make more advanced changes by clicking on the ‘Show Advanced Settings’ button – the screen will change as shown below. You can scroll up to see (and change if necessary) more advanced details. Click on the ‘Finish’ button to save your edits and to close this window. You will be back at the ‘Verify Configuration’ window. You can close this window by using the ‘x’ on the top right hand corner of the window. Then, you will be back at the project window.

Before running the project, first click on the downward pointing arrow next to the ‘Nexus 4’ icon, then select the ‘Nexus 5X’ item from the drop-down list (remember that we already have created a Nexus 5X AVD). This is shown by the red arrow in the figure below. Now we are ready to run the project on our emulated Android device.

STEP 9: Running The Project Using An Emulated Android Device

To run this project on the Nexus 5X AVD emulator that you have created, click on the ‘Run’ button – the one in Android Studio’s toolbar that looks like a green-colored right pointing arrow, as indicated by the red arrow in the figure below. Another window will pop-up and, after a while, the screen will look like the one shown below.

Note the warning message (on a yellow background) stating that ‘No USB devices or running emulators detected’. You can safely ignore this message – you have not connected an actual Android device and the emulator has not started yet. Also note that the Nexus 5X emulator has been pre-selected by default. Click on the ‘OK’ button.

NOTE FOR AMD BASED PC: Here is where the difference between an Nvidia-based PC and an AMD-based PC is clearly demonstrated. As soon as you press the ‘OK’ button, Android Studio will try to load the Nexus 5X AVD. On a AMD-based PC, this will fail and an error message window will pop-up (shown below) saying ‘Cannot launch AVD in emulator’ and will display the reasons why it failed listed below that. Apparently this a driver/libGL error – search the web for a possible solution for the time being until AMD/Google decides to fix the problem.

The Nexus 5X AVD will start and after a while, the AVD will appear displaying the flashing ‘Android’ sign (see below). Then the AVD will display the home screen for a short while (see below), after which the ‘Hello World!’ message will appear on the AVD's screen (see below). This means that the Nexus 5X AVD is set up correctly and is working perfectly.

Note the small vertical window to the right of the AVD (see below). This contains all the controls for the AVD – which includes the power button, the speaker volume controls, the screen rotation controls, the camera button, the search button and the navigation buttons. At the extreme top are the minimize and exit buttons. At the extreme bottom is a row to three horizontal dots – clicking on this will bring up another window (shown below) where more extended controls are located. You can play with the controls if you wish. Then click on the ‘x’ located at the top right of this window to close it. To close the AVD, click on the exit button located on top of the control window. You will be back at the project screen (shown below).You can close the ‘Hello World’ project anytime by clicking on ‘File’ menu and selecting ‘Close Project’.

STEP 10: Running The Project Using An Actual Android Device

We have successfully tested the ‘Hello World’ project on the AVD emulator. However, our ultimate goal is that the project should run on an actual Android device (a smart phone, for example). In order to do this, you need to connect that device to our development PC (the PC on which Android Studio is currently running) using a proper USB cable and the proper USB ports.

First you need to enable USB debugging on your Android device. Usually this setting can found under ‘Settings’ and ‘Developer options’ but it can vary from device to device. On some Android devices, ‘Developer options’ may need to revealed as they are hidden by default. If unsure, consult your ‘User’s Manual’ or the manufacturer’s web page for the information on how to enable USB debugging. The screenshot shown below is the already revealed ‘Developer options’ for the Nexus 5X.

If you find an item labelled ‘Revoke USB debugging authorizations’ on your Android device, select that and clear all previous authorization by selecting ‘OK’. Note that if this item is not present on your Android device, you can safely assume that your PC is automatically authorized. The screenshot shown below is the ‘Revoke USB debugging authorizations’ for the Nexus 5X.

Next we have to make sure that the proper USB cable is used. The manufacturer of your Android device usually provide you with one – use that cable and none other. Unfortunately, the Nexus 5X smartphone comes only with type C USB connectors at both ends, so it would be impossible to make connections to a PC with type A USB connectors. Should this be the case with your Android smart phone and your PC, it would mean getting another USB cable for the connection between your Android smartphone and your PC.

You also have to make sure that the USB port to be used on your PC is working. Test this port out first by plugging in a thumb drive (or any other USB device) and if the PC recognize this device, you can safely say that the USB port is working.

Now make sure that Android Studio is running the ‘Hello World’ project. Then connect your Android smart phone to your PC using the USB cable. Dismiss any file manager window on your PC if any pops up – also ignore any warning messages that may also pop up.

Then click on the ‘Run’ button in Android Studio’s toolbar. As usual, the ‘Select Deployment Target’ window will pop up as shown below. Note that the ‘LGE Nexus 5X (Android 7.0, API 24’ item is selected by default. You may need to authorize the USB connection to the smart phone for debugging with the PC’s RSA key by selecting ‘OK’ on your smart phone (see below). Then click the ‘OK’ button to run the project on your Android phone device.

If everything is set up correctly, you should see the ‘Hello world!’ message displayed on your Android device’s screen (see below). If not, see if there are any messages on your Android Studio status screen of your PC. If the message mentions authorization (for example), then, most probably you have forgotten to set USB connection authorization on your device. Do it now and retry running the project again. The important thing to note here (if unsuccessful) is that Android Studio will display some message and this usually gives you a clue on what is wrong. If you still run into problems, then I suggest searching the Internet with your problem.

You can now close the window on your Android device (usually using the ‘Back’ key). If you examine the apps on your device, you will find an app labeled ‘Hello World’ (see below). This is, of course, the ‘Hello World’ app file (usually with a .apk extension) which Android Studio has downloaded for you. You can delete this file if you so wish. By the way, before you put your Android device aside after testing more new apps developed using Android Studio, remember to disconnect the smart phone first and then switch off USB debugging.

To close the ‘Hello World’ project on your PC, click on ‘File’ and the ‘Close Project’ menu items on Android Studio. You will be back to the welcome screen and the ‘Hello World’ project will be listed on the left hand side pane (see below). To restart (or reload) the same project, make sure that the project is selected and then double-click that item – the project will then be started.

Summary Of Steps

  1. Disable Libre Office from using Java.
  2. Use Synaptic Packet Manager to remove all OpenJDK entries for ‘icedtea’.
  3. Download and install Oracle's Java JDK (or SE).
  4. Tell LMDE2 the default Java to use.
  5. Set system variables for new Java.
  6. Download and install 32-bit libraries.
  7. Download and install Google's Android Studio.
  8. Run Google's Android Studio setup.
  9. Install launcher for Google's Android Studio.
  10. Configure SDK for Google's Android Studio – download and install SDK components.
  11. Install additional SDK packages as you wish.
  12. Create a new project on Google's Android Studio.
  13. Create a new AVD (Android Virtual Devices) for testing the new project.
  14. Run the new project on the AVD to test it.
  15. Run the same project on an actual Android device.

Final Words:

That's it. You now have a 64-Bit LMDE2 PC which can be used to develop Android software. If you are an experienced Intellij, Android Studio, Java and Android programmer, enjoy! For those people who is new to Android Studio or Java programming, here are some links which I recommend you visit in order to learn about Android programming.

To learn about the Intellij IDE (on which the Android Studio is based), visit for a tutorial on this.

To learn how to use Android Studio for developing Android software, visit for a tutorial on this.

If you are new to Java, then I would recommend searching the web for tutorials and the books ‘Java For Dummies, 7th Edition’ and ‘Head First Java, 3rd Edition’ as a guide.

If you are new to Java Programming for Android, then I would recommend searching the web for tutorials and the book ‘Java Programming For Android For Dummies’ as a guide. There is also another book by the same author but is more ‘advanced’ and is targeted towards Android developers. The title of this book is ‘Java Programming For Android Developers For Dummies’.

Happy computing!

No comments:

Post a Comment