On a newly-installed and updated LMDE 2, the OpenJDK JRE (Java Runtime Environment) 7 is installed and set as the default Java. This can be verified by executing the following in a terminal:
The output is as follows:
java version "1.7.0_21"
OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-5)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
Although whether the JRE or JDK version of OpenJDK 7 is installed by default is not clearly indicated in the output, it can be easily verified by executing the following:
update-alternatives --list java
The output is as follows:
This clearly indicate that only the JRE (versions 6 and 7) is installed by default. However, Google’s Android Studio requires the full Java JDK, and the recommended version is Oracle’s Java (JDK or SE 7 and above). So, you can either delete the OpenJDK 6 and 7 JRE’s and install Oracle's Java JDK 8 in it's place, or install Oracle’s Java JDK 8 and keep the OpenJDK 6 and 7 JRE’s. Either way you have to tell Linux Mint which Java is the default by using the ‘update-alternatives’ command. This ‘how-to’ implements the first option – delete the OpenJDK 6 and 7 JRE’s and install Oracle's Java JDK 8 in it’s place.
Use the following steps to install Oracle’s Java SE and Google’s Android Studio:
STEP 1: 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 8u45 (or 1.8.0_45). It is also recommended that you download the API docs and demos (plus 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:
tar xzvf jdk-8u45-linux-x64.tar.gz
tar xzvf jdk-8u45-linux-x64-demos.tar.gz
unzip jdk-8u45-docs-all.zip -d jdk1.8.0_45
The last 2 commands in the above is only applicable if you have downloaded the demos and the documentation. The 2nd command above will create a ‘jdk1.8.0_45’ directory in the Downloads folder while the last 2 commands above (if applicable) will create the ‘sample’, ‘demo’ and ‘docs’ directories under the ‘jdk1.8.0_45’ directory in the Downloads folder.
Now execute the following commands:
sudo mv jdk1.8.0_45/ /usr/lib/jvm/
The first command will move the whole ‘jdk1.8.0_45’ directory to the ‘/usr/lib/jvm’ directory – where the root of the current OpenJDK 6 and 7 JRE’s resides. The second command will place you back into your home directory. If you are curious (like me), you can do a ‘ls -la /usr/lib/jvm’ command to find out what resides in this directory. Don't be surprised to find both the OpenJDK 6 and OpenJDK 7 directories listed there – why I don’t know.
Notice that the owner and group of the ‘jdk1.8.0_45’ 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_45
STEP 2: Set Up Default Java To Oracle's Java JDK 8
The next thing to do is to tell LMDE 2 where Oracle Java JDK resides. For this we use the ‘update-alternatives’ command. Execute the following commands one by one 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_45/bin/java" 1500 --slave "/usr/share/man/man1/java.1" "java.1" "/usr/lib/jvm/jdk1.8.0_45/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. Just remember that Open JDK 7 Java is the default Java for current LMDE 2 system – however, since we installed the above links with a priority of 1500 (higher than OpenJDK's 1071), the default Java was 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 contain the following line:
link currently points to /usr/lib/jvm/jdk1.8.0_45/bin/java
then everything have been set correctly.
STEP 3: Remove OpenJDK 6 and 7 JRE’s
Then we have to remove the OpenJDK 6 and 7 JRE’s. To do this, we have to turn to the Synaptic Packet Manager. Launch Synaptic and enter ‘icedtea’ into the search box. Then mark the following items for complete removal:
Click the ‘Apply’ button to remove the marked files and then close Synaptic. You can do a ‘ls -la /usr/lib/jvm’ command in the terminal to check whether both the OpenJDK 6 and 7 JRE’s has been successfully removed. Note that the Gnu Compiler for Java (gcj version 4.8) will be automatically installed, probably as a replacement for OpenJDK Java, but this should not affect Oracle's Java which is now set as the default in the previous step.
A quick check on the current version of the Oracle's Java can be performed by executing the following command in a terminal:
If the output for the command is:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
then Oracle JDK 8 has been set up properly.
STEP 4: Set the System's Environment Variables and Paths
Now we have to set the environment variables and paths correctly for the whole LMDE 2 system. If you have already set these variables previously, then you can safely skip this step. If not, 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 the following lines at the end of the file.
Save the file and close it. Note that, upon system startup, these will set the JAVA_HOME and PATH environment variables for the whole system. The 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. This will enable the ‘javac’ command to be executed from any directory.
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 in a terminal:
If you see the string ‘jdk1.8.0_45’ in the output to the above commands, then you have successfully removed OpenJDK 7 JRE and replaced it with Oracle 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 1, STEP 2 and STEP 4 above. Just make sure that you change the version number to the new version in the commands shown above.
STEP 5: Install 32-Bit Libraries
Since you are using the 64-bit version of LMDE 2, run the following commands in a terminal to download and install some necessary 32-bit libraries:
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6 lib32gcc1 lib32tinfo5 libc6-i386
Note that, if you fail to install these packages, you will not be able to install Android Studio without running into errors – especially during the ‘Downloading SDK Components’ stage.
STEP 6: 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. Then start a terminal and execute the following command:
This will decompress the contents of the zip file downloaded into a new directory called ‘android-studio’ in your home directory. To start Android Studio setup, execute the following commands, one by one:
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 screen similar to the one shown below, will appear. Click on the ‘Next’ button to continue.
The next screen 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 the next screen 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 screen. You can read up more on this technology at the URL shown on the screen – remember that the web page there is for Windows only – to read more on Linux and Virtualization Technology, click here. Then click on the ‘Next’ button.
The next screen that appears as shown below is where you agree to accept the license for installing Google’s Android SDK. Note that this is a must and cannot be skipped if you want to develop software for the Android platform. Click on ‘Accept’ and the the ‘Finish’ button.
The SDK components will begin downloading as shown in the screen below.
Once downloading and installation is completed, a log window will appear as shown. Click on the ‘Finish’ button.
The next screen shown is the Android Studio IDE itself (shown below). You have now successfully installed Android Studio on your LMDE 2 PC.
Notice the ‘Check for updates now' on the IDE window – click on ‘Check’ and if you already have the latest version, a window similar to the one shown below will pop-up.
If there are any updates, a window similar to the one shown below will pop-up.
Click on the ‘Update and Restart’ button. Android Studio will close and the updates will begin downloading as shown.
Once the updates have been installed, Android Studio will start again. You can now pause and admire your handiwork, then close Android Studio.
Remember that, at the moment, you have to start a terminal, change to the correct bin directory and then launch ‘studio.sh’ 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:
- Right-click on an empty portion of your desktop and select ‘Create a new launcher here...’
- 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 ‘studio.sh’ file in your home 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.
- For the icon, click on the rocket icon, and navigate to your home directory, double-click on android-studio and bin directories and then select the ‘studio.png’ file. Then click ‘OK’, followed by another ‘OK’ to dismiss the ‘Launcher Properties’ window.
If you had created a menu item, you can also place an Android Studio icon in you LMDE 2 panel (see below). Locate the Android Studio item under the ‘Other’ category in your menu, right-click on this item and then select the ‘Add to panel’ item. The Android Studio icon will then appear in the panel – single click on this icon to start Android Studio.
STEP 7: Configure SDK Manager
On the Quick Start screen of the Android Studio, click on ‘Configure’ and the ‘SDK Manager’ item. The SDK Manager (as shown below) will start and if there are any update packages, it will be shown on the ‘Install xx packages...’ button (where xx = number of update packages).
Click on that button, and the ‘Choose Packages to Install’ window will appear as shown below. Click ‘Accept License’ for all the items followed by a click on the ‘Install’ button.
The SDK Manager window will re-appear and the packages will be downloaded and installed as shown below. Once the packages has been installed, a window may pop-up saying that the SDK Manager has been updated and Android Studio needs to be restarted for the updates to take effect – do so as per the request.
Now it's time to check what has been installed so far. On the SDK Manager window all installed packages are marked ‘Installed’ under the ‘Status’ column. Note that SDK packages has already been installed for Android M - the latest Android version (API 22) 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 smartphone running Android version 4.4.2 (KitKat), so the packages marked as shown below, was selected to be installed. The ‘Install 6 packages...’ button was then clicked upon and the packages were installed.
STEP 8: Configure AVD Manager
Click on ‘Tools’ and ‘Manage AVDs...’ from the Android SDK Manager menu and the Android Virtual Device (AVD) Manager window similar to the one shown below will appear.
Notice that an AVD called ‘Nexus_5_API_22_x86’ has already been defined by Google. As the name suggest, this is for the Nexus 5 Android smartphone and you can view it's settings by selecting the AVD and clicking on the ‘Edit’ button. The window as shown below will appear. Take special note of the warning that appears as the last line in this window.
Make a note of each of the settings as this provide a guide for setting up an AVD of your own later. Close the ‘Edit’ window when done and you will be back in the AVD Manager window. Notice that there is another tab labelled ‘Device Definitions’. Clicking on this tab will show a window similar to the one below and they contain a list of generic AVD device definitions. You can use this list as a starting point for creating your own AVD later.
For now, let's take a look at the pre-defined Nexus 5 AVD. To start an AVD, make sure that you click on the ‘Android Virtual Devices’ tab and then on the ‘Start’ button. A window labelled ‘Launch Options’ (shown below) will appear.
Click on the ‘Launch’ button to launch the AVD. Two things will happen normally – one is a ‘Starting Android Emulator’ window (shown below) and the other is the outline of the Nexus 5 AVD (also shown below).
If, for some reason, the loading was slow and/or errors occured, it is possible that Intel’s Virtualization Technology plus Linux’s KVM (Kernel-based Virtual Machine) features are NOT supported in your PC. This will often happen if your PC is NOT using the newer version of an Intel CPU – for example your PC is using an old AMD CPU. It also can happen if you don’t have Intel’s Virtualization Technology enabled in BIOS and you are using Intel Atom x86 CPU/ABI in your AVD. The error may look like the one shown below. If you see this you may want to use a PC with Intel’s Virtualization Technology plus Linux’s KVM features. You can close this window by clicking on the ‘Close’ button.
Once the AVD has finished loading without any errors, the Nexus 5 AVD will appear in it’s full glory (see below). That was fast, wasn’t it? This is only possible with Intel’s Virtualization Technology plus Linux’s KVM feature and with the PC’s BIOS set up correctly to use this technology.
As with an actual Android smartphone, you need to unlock the phone before you can use it (ignore any messages about backup). Click on the padlock icon on the AVD and swipe (move the cursor) upwards to unlock the device. The screen will change to one shown below.
Click on the ‘OK’ button and the main home page of the phone will appear (see below).
Click on the ‘Apps’ button (the center icon at bottom) and the screen will change to one as shown below.
Click on the ‘OK’ button and all the application software that were included with the AVD will be shown (see below).
To test out an example software, click on the ‘Browser’ icon – if your PC is connected to to the internet, you should see a screen similar to the one shown below.
Type something into the Google search box, using the on-AVD-screen keyboard – for example ‘linux mint’, then click the search icon. The page shown below will appear.
Click on the ‘Linux Mint’ that appears to go to the Linux Mint home page. If everything works, the Linux Mint home page will appear (see below).
You can now play around with the Nexus 5 AVD – notice how fast the response is, thanks to Intel’s Virtualization Technology plus Linux’s KVM features. You can safely close the AVD by clicking on the ‘x’ on the top right hand of the window. You will then be back to the AVD Manager window.
STEP 9: Setting Up Your Own AVD
If, for some reason or other, the Android device that you possess is not listed under the Device Definitions tab of the AVD Manager, you can create one to correspond to your device. First make sure that you have selected the Device Definitions tab, then click on the ‘Create Device’ button. You should see a screen similar to the one shown below.
Now make sure that you have all the details for your Android smartphone ready – search for it on the internet or use your User’s Manual if the details are present in there. As an example, the author has entered the details for his Samsung Galaxy Note 2 in the figure below, then clicked on the ‘Create Device’ button.
You will be back to the AVD Manager window with the ‘Device Definitions’ tab selected. Notice that the device you created will be in the device list (you may have to scroll up or down to see the created device). The screen will look like the one shown below.
Note that you have only created a definition for the device but NOT an AVD for that device. To create an AVD, select the newly created device, then click on the ‘Create AVD’ button. You will see a screen similar to the one below. Notice that the 'AVD Name', the 'Device', and the 'Target' entries have been pre-entered from the new device definitions.
You can edit the entries if you so wish, but for this tutorial, leave the entries alone. Note however, a warning message that no CPU/ABI system image has been selected yet will appear at the bottom of the window – do so now by clicking on the down-arrow to the right of the CPU/ABI item on the window and select the CPU as per your device specification. Since my Android smartphone is using the ARM processor, I decided to use the ‘ARM (armeabi-v7a)’ CPU/ABI as I will be testing software on that smartphone itself (more about this later). The ‘Hardware keyboard present’ item was also deselected. Notice that the warning message has now changed to ‘No skin selected’. Change the skin to ‘No skin’ by clicking on the down arrow on the Skin item and selecting ‘No skin’ from the list. The screen will now look like this.
If you have a webcam on your PC, you can use it as your rear camera and/or your front camera. Click on the down-arrow on the ‘Back Camera’ and/or ‘Front Camera’ and select ‘Webcam0’ for the entries. You can safely skip these items or use ‘Emulated’ for both items if you do not have a webcam on your PC. The RAM size was pre-selected – you can change this if you wish. Also, if you wish to have a SD card on your AVD, specify the size of this card – I have entered 200 as an example here. To make the AVD perform faster, the use of the host GPU is highly recommended – I have enabled this in the screen shown below.
Click the ‘OK’ button to create the new AVD. If there are no errors, the result of creating the new AVD will be shown on the next window (see below).
Click on the ‘OK’ button to dismiss the window and you will be back in the AVD Manager window with the newly created AVD already selected (see below).
To start this AVD, click on the ‘Start...’ button then click the ‘Launch’ button on the Launch Options window that appears next. If the Google thank you window appears (see below), click on the ‘Proceed’ button to dismiss it.
The AVD will now load – at a very much slower rate than the Nexus 5 AVD! First, the screen shown below will appear with a flashing ‘android’ sign in the middle of the display.
After a long while, the screen will change as shown below.
Click the ‘OK’ button and the screen will change as shown below.
You can go ahead to play around with this device. Just note that it is very slow to respond to clicks as compared to the Nexus 5 AVD. You can safely close this AVD by clicking on the ‘x’ on the top right hand of the window. You will then be back to the AVD Manager window.
If your PC is using an Intel CPU and you have set up your BIOS accordingly, you can edit the AVD (by clicking on the ‘Edit...’ button) for the newly-created device and change the CPU/ABI to the ‘Intel Atom (x86)’, then click the ‘OK’ button twice to re-create the AVD (see below).
To start the AVD, click on the ‘Start...’ button then click the ‘Launch’ button on the Launch Options window that appears next. The AVD will now load – at a very much faster rate than previously. This illustrate the power of using the Intel Atom (x86) CPU/ABI together with a capable Intel CPU and Intel’s Virtualization Technology plus Linux’s KVM features with Android Studio on your development PC! Just remember to re-create the AVD with the actual CPU (ARM in my case) if you plan to test out software on the emulated device – it does not matter if you use Intel Atom CPU/ABI and develop software for testing on the actual device itself. Close the AVD when you have finished playing around with it.
STEP 10: Create a New Project Using Android Studio
Now that you have successfully installed Oracle’s Java SE and Google’s Android Studio and set up an AVD, 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, or your actual Android device.
Launch Android Studio (if it is closed) and dismiss any tip screen if it appears (see below) by clicking on the ‘Close’ button. Start a new project by clicking on the ‘Start a new Android Studio project’ item from the Welcome screen (see below also).
The ‘New Project’ screen as shown below will appear – fill in the details for the ‘Application name’ and ‘Company Domain’ as shown. 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’ screen 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’ screen will appear next (see below). Select the ‘Blank Activity’ item if it is not pre-selected. Then click on the ‘Next’ button.
The ‘Customize the Activity’ screen 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.
The next screen may look like the one shown below – if not skip to the next paragraph. Note the ‘Rendering Problem’ message which states that ‘Rendering failed with a known bug. Please try a rebuild.’ Click on the ‘rebuild’ item, and wait a while for the renderer to rebuild.
After the renderer has finished building, a screen similar to the one shown below will appear. Note that it does contain a graphic of a Nexus 4 device with the ‘Hello world!’ text on it. This, however, is NOT the output of the project on your AVD.
To run this project on your 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) and the ‘Choose Device’ screen (see below) will appear. Note that the ‘Launch emulator’ item has been selected and that you don't have any other running device (‘Nothing to show’ will be present in the top half of the window).
Click on the ‘OK’ button and the AVD will start and the screen will change to the one shown below.
Unlock the AVD (like a regular Android smartphone) to run the project and the output will appear on the AVD (see below).
After admiring your handiwork, close the AVD and you will be back at Android Studio (see below). Notice that you are now viewing the Java source code for the project under the ‘MyActivity.Java’ tab. For the time being, just ignore any messages shown in the status area at the bottom of the Android Studio’s screen.
To change back to activity screen, just click on the ‘activity_my.xml’ tab and the screen will change to the one shown below.
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 smartphone, 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. But first you need to enable USB debugging on your 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.
If you find an item labelled ‘Revoke USB debugging authorization’ 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.
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. 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 device to your PC using the USB cable. Dismiss any file manager window on your PC if one pops up. Then click on the ‘Run’ button in Android Studio’s toolbar. As usual, the ‘Choose Device’ window will pop up as shown below. Note that the ‘Choose a running device’ item is selected and that device is listed as shown (a Samsung GT-N7100 in this case). Click the ‘OK’ button to run the project on your Android 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 labelled ‘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 switch off USB debugging first.
That's it. You now have a 64-Bit Linux Mint Debian Edition 2 Cinnamon 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 https://www.jetbrains.com/idea/documentation/ for a tutorial on this.
To learn how to use Android Studio for developing Android software, visit https://developer.android.com/training/index.html 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, 6th Edition’ and ‘Head First Java, 2nd 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’.