There has been a lot of news lately about Google and the future of Android (search the Web for this term to read all the news). First 'fragmentation' then 'updates' and 'Google vs Oracle court case', and 'beyond Linux' and so on. Should you be worried? I suggest that you concentrate on program development for Android and let the chips fall where ever they may. Google is too big to fail - that said, it may take a very long while for it to so. So, for the time being, Android program development is the way to go. Enough of the political bit, and let us concentrate on Android et al.
Before we start off on our journey, the author will assume that you have installed the latest version of Ubuntu - currently at version 18.04 LTS (codenamed Bionic Beaver) and updated it.
Also, note that the author will assume that you have installed the proper propriety video drivers for your Ubuntu PC. The process for enabling the propriety video drivers for your PC can be found by clicking on Show Applications -> Software & Updates -> Additional Drivers and wait for the drivers to be updated, then make your choices - Nvidia, ATI/AMD or Intel. Wait for the video drivers to be installed and then restart the PC.
This is the only way for OpenGL ES (or GLES) to be installed for the PC. OpenGL ES is required by Android to make 2D/3D graphics processing faster through Hardware Acceleration. Note that this 'how-to' is based on a Nvidia video card equipped PC, with the propriety video driver installed.
One peculiarity of Ubuntu 18.04 LTS is that it requires that the Kernel Virtual Machine (KVM) permission is given to the current user, else the user won't be able to create an emulated Android Virtual Device (AVD). The current user may see the message as shown below:
If the 'Troubleshoot' message is clicked, the following screen will appear:
Note that the message states 'Grant current user access to /dev/kvm' and is the solution to the problem. Note that this problem DOES NOT occur on any other OS; just Ubuntu 18.04 LTS - why it should be is anybody's guess.
To overcome the permission issue, open a terminal and follow the steps below:
- Install the following packages by executing:
sudo apt install qemu-kvm cpu-checker
- Then execute the following command:
kvm-ok
If you see the following respond:
INFO: /dev/kvm exists
KVM acceleration can be used
You can proceed to the next step.
- Check if a group 'kvm' exist on your PC by executing the command:
cat /etc/group | grep kvm
This should show as a response:
kvm:x:128:
The number shown may be different for your PC. You should NOT see anything left to the final ':', i.e., there are no users in the 'kvm' group.
- To add your user to the 'kvm' group, execute the following command:
sudo adduser <user_name> kvm
Replace <user_name> with the user's log-in name. To check, execute:
cat /etc/group | grep kvm
You should see the following:
kvm:x:128:<user_name>
- If you execute the following:
sudo ls -la /dev/kvm
you should see the following response:
crw-rw---- 1 root kvm 10, 232 May 9 10:14 /dev/kvm
This shows that the ownership of '/dev/kvm' now belongs to the 'kvm' group and your user is part of that group.
- Restart your PC to make the group changes effective.
This 'how-to' was tested on the following hardware and found to be working:
- Gigabyte GA-Z79-HD3 Motherboard
- Intel Core i5-4590 CPU (3.3 GHz)
- Kingston 16Gb DDR3 HyperX RAM
- Nvidia GTX 750Ti PCI-E Graphics Card
STEP 1: Install Google's Android Studio
Before you do anything else you need to remember that you are using the 64-bit version of Ubuntu, so it is important to note that Android Studio requires some 32-bit libraries in order to run properly. You must install the necessary packages by executing the following command in a terminal:
sudo apt install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
Note that, if you fail to install these packages, you will not be able to use Android Studio without running into errors
Now it's time to download and install Google's Android Studio. Point your web browser to here and click on the DOWNLOAD ANDROID STUDIO button (the button will turn green) to start the download (see figure below). While you are there, can read the read the DOWNLOAD OPTIONS and the RELEASE NOTES by clicking on the appropriate buttons.
Then, on the next page, place a checkmark accepting the terms and conditions of Android Studio and then click the download button as indicated by the red arrow. Wait for the download to finish.
NOTE: The downloaded file is named 'android-studio-ide-173.4720617-linux.zip' and is the currently the latest version of Android Studio (as of May 2018). The version number shown may be higher than this as Google is constantly updating it.
Meanwhile, the web page for Android Studio will change to the one shown below.
NOTE: On the same web page, you will find a URL labeled 'Build your first app'. You can click on this link and bookmark that web page for a continuation of this 'how-to'. Links will also be given for Udacity learning courses, meeting Android Studio, and the install guide. If you click on the item 'install guide' and you scroll down to the part on Linux, you will find the part about the 32-bit libraries there.
Now that you have downloaded Android Studio, it is time to get it installed. To install Android Studio, first, start a terminal and then navigate to the Downloads folder. Then execute the following command:
unzip Downloads/android-studio-ide-173.4720617-linux.zip
This will decompress the contents of the downloaded zip file into a new directory called 'android-studio' which can be found in your home directory. Note that this installation can only be run by you - if you wish other users to access Android Studio, then use the '/opt' directory instead (see the Android Studio install guide).
To start Android Studio setup, execute the following commands in a terminal, one by one:
cd android-studio/bin
./studio.sh
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 of importing all the old settings. Else, just press the 'Enter' key to accept the default 'Do not import settings'.
Android Studio will begin loading as shown in the figure below.
After a while, the Setup Wizard "Welcome" screen similar to the one shown below, will appear. The Next button was clicked in order to continue.
The next screen ("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 to continue.
The next screen (see below) is the "Select UI Theme' where you can select the type of User Interface (UI) for Android Studio. For this 'how-to' the IntelliJ UI was selected - but you are free to choose any UI which please your eyes.
The next screen (see below) is the "Verify Settings" 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 next screen will appear.
If you have Intel's Virtualization Technology enabled in your PC's firmware and Linux kernel, then it will be detected as shown on the "Emulator Setting" screen. You can read up more on this technology at the URL shown on the screen. Then click on the Finish button.
The SDK components mentioned in the "Verify Settings" screen will begin downloading as shown below. Wait for the download and installation of the SDK components to finish.
Once downloading and installation is completed, and you see the 'Android SDK is up to date' message in the line, 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 on your Ubuntu 18.04 LTS PC.
There are a number of items on the Welcome Screen - some of which you will use very often and some not. There are items which allow you to manipulate an Android project file - from starting a new project, opening an existing project, using Version Control on a project, managing APK files, and importing a project file and Android code sample. There are 2 other items found on the initial IDE - one is for configuring the IDE (the 'Configure' button) and the other one is for seeking help (the 'Get Help' button). For this 'how-to', only the first item in the list, 'Start a new Android Studio project', and the 'Configure' item will be used. For an explanation of the rest of the items, either use the 'Get Help' item or use the Internet.
NOTE: The latest version of Android Studio has a new look which differs from the previous versions. One of the major differences is the way Android Studio handle updates - if there are any, the last line on the IDE window will contain an additional item - the 'Events' item with a green balloon to the left.
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! Click on the 'Configure' button and select the 'Create Desktop Entry' item and a window will pop-up - click the 'OK' button to close the window.
Close Android Studio by clicking on the 'x' on the top right of the window. Ignore any warnings on the terminal and close it.
Then click on the 'Show Applications' and locate the Android Studio icon in it. Then right-click on the icon and then select 'Add to Favorites' item. The Android Studio launcher (as shown by the red arrow in the screenshot below) will then remain permanently in the dock until you remove it. You can now test whether this Android Studio works by clicking on the said icon.
If you want to launch Android Studio from anywhere using the file 'studio.sh', 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
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 Android Studio in a terminal from any directory.
STEP 2: Configure SDK Manager
Launch Android Studio again if you have not already done so. Notice the 'Configure' on the last line of the screen - click on it and then click on the 'SDK Manager' item (see below).
The 'Default Settings' screen similar to the one shown below will appear.
Note that the 'Android SDK' item is automatically selected on the left pane of this screen. Other items are listed in the left pane and are available for you to use, but for the time being, keep the selection on the 'Android SDK' only in the left pane.
The column to note is the 'Status' column at the right-hand side of the screen - it is where the screen indicates whether the package has been installed or any updates are available for any package. For the purpose of this 'how-to', a 'package' can include other packages - but this screen will only show the 'main' package.
The location of the 'Android SDK' is clearly stated at the top of this screen, and you can change its location if you wish - but for the purpose of this 'how-to', keep it as it is.
Note also that the tabs below the SDK location are preselected for the 'SDK Platforms'. To change tab, all you need to do is to click that tab - for example, click on the 'SDK Tools' tab, and you will see the contents of that tab (see below).
NOTE: There are lots and lots of SDK tools listed here. Only those tools that are essential to initially build a project have been installed. You are free to install any other extra tools as you so wish.
If you see any items with a minus sign instead of a check mark and you see the text 'Update Available: xx.x' (where x can be any number), then it indicate there are updates available for that item.
NOTE: From now on, I suggest that you check if there are any updates by using the Events green balloon or the SDK manager. This should be done every time you start Android Studio.
If you click on the 'SDK Update Sites' tab, you will see URL's for the sites (see below) - do not change anything on this screen at this time.
Now click the 'SDK Platforms' tab again - keep it at that tab for the moment. Note the 'Show Package Details' box at the bottom of the screen - at the moment it is not selected (i.e., no check mark has been placed there). Click on the box to select it - the display will change as shown below.
This display screen will show more details on the packages installed so far - including their API level, its revision number and as mentioned previously, it's status. Note that it even includes packages for the new Android P. If you want to try this preview, select the item for downloading as described below.
NOTE: If you decide to use the latest Android P do so as the latest Android version is backward compatible.
Based on your requirements, you may decide to install more packages. For example, the author has a Google/LG Nexus 5X smartphone running on Android 8.1 (Oreo) - so it was decided to install the additional packages (plus the Android P) as shown by selecting the box next to its names. Note the 'Download' icons that appear as soon as you select the boxes for the items (see below).
You are free to select any packages to download and install, depending on the actual Android devices that you possess. Just select them (you have to scroll down the display for more packages).
Then click on the 'Apply' button. The 'Confirm Change' screen will appear (see below). Then click the 'OK' button.
The 'License Agreement' screen will appear next (see below). Click on 'Accept', followed by a click on the 'Next' button. Note that if you have multiple items such as the one shown, don't forget to click on the 'Accept' button as many times as required.
The 'Component Installer' screen will appear next (see below) and download of the components will start.
NOTE: If you deal with Android TV and/or Android Wear, make sure that you download these items.
The ARM system image more closely matches most Android devices using these processors, but requires the processor to be emulated and is thus very slow. The Intel x86 Atom system image is potentially quite a bit faster, using the Linux's KVM support mechanisms to execute the code in a partially native way. You can try the x86 for speed, and fall back to the ARM if you have compatibility problems.
Support for Google specific Android APIs like the Android Google maps API, are not provided with the standard Android system images. They need to be installed separately using the SDK manager. To use these APIs with an x86 system image you need to also install the Google APIs (x86 System Image) for the same API level.
The difference between a 32-bit and a 64-bit processor is self-evident and can be found easily on the Internet. Examples can be found here or here.
Wait for the download to finish (it may take some time to complete), then click the 'Finish' button (see below).
You will be back at the 'Default Settings' screen of the Android SDK (see below). Inspect the packages that were downloaded and installed to make sure that they are correct. If any errors are found - such as downloading errors - then try again. Once this is successful then click the 'OK' button.
You will be back at the welcome screen of Android Studio (see below). Close Android Studio by clicking on the 'x' on the top right hand of this screen.
STEP 3: Create a New Project Using Android Studio
Now that you have successfully installed Google's Android Studio and configured it, it's time to use it 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 Android Virtual Devices (AVD), 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' screen as shown below will appear - fill in the details for the 'Application name' to 'Hello World', and 'Company Domain' to 'any.company.com' 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.
NOTE: You can change the package name by clicking on the 'Edit' button on this screen - but I suggest that you keep this package name - at least for this 'how-to'. Likewise, you can also enable C++ and Kotlin (search the Internet if you are not familiar with this) support by enabling the appropriate boxes - but for this 'how-to', leave them off.
The 'Target Android Devices' screen will appear next (see below). Make sure that the 'Phone and Tablet' item is selected. The 'Minimum SDK' is preselected 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 of which minimum SDK to select, you can click on the 'Help me choose' item. For this tutorial, leave it at the preselected minimum SDK. Then click on the 'Next' button.
NOTE: If you are developing any projects for Android Wear and/or TV, then select the appropriate buttons. The Android Auto item enables you to add support for it to your existing application. It will enable your app to work on both car and phone screens. Android Auto handles most of the work to adjust each application's user interface to the screen on which it is displayed. Note that to enable your app for Wear/TV, your app must target Android 5.0 (API level 21) or higher. Likewise, for Android Things, your app must target Android 7.0 (API level 24) or higher.
The 'Add an activity to Mobile' screen will appear next (see below). Select the 'Empty Activity' item if it is not preselected. Then click on the 'Next' button.
NOTE: There are lots of activities to choose from - you can scroll through the available ones and pick one to suit your app. According to Google, activities are one of the fundamental building blocks of applications on the Android Studio platform. They also serve as the entry point for your interaction with an application and are also central to how a user navigates within an application or between applications. For further reading, go here.
The 'Configure 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 'Next' button.
NOTE: There are two other radio boxes that you can use - one is labeled 'Generate Layout File' and the other is labeled 'Backwards Compatibility (AppCompat)'. The 'Generate Layout File' allows you to generate an XML file for the activity, while 'Backwards Compatibility (AppCompat)' is letting you know that if you uncheck it, then you'll be including and using the library Activity instead of AppCompatActivity. At the moment, both of these are enabled (i.e., they both have check marks). Leave them enabled for the time being. Use Google to search for more information on these items.
The 'Component Installer' screen (see below) may appear next and this is where Android Studio checks for any components that may be required to be downloaded and installed. Once that is done, click on the 'Finish' button.
Android Studio (the 'Gradle' part anyway) will then start building the project as shown below. This may take some time to complete so be patient. 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 Java source code for this 'Hello world' project in the Android Studio IDE.
After the system has finished building the project, a screen similar to the one shown below will appear.
If a 'Tip of the Day' screen appears, you can safely close it by clicking on the 'Close' button. You can, if you wish to, also clear the box labeled 'Show Tips on Startup' to disable this feature.
NOTE: For those users who are new to Android Studio (and the IntelliJ) user interface, the various buttons, menu items, tabs, etc, poses a very big challenge - for example, what are the purpose of the various buttons? Do not despair as the Android Studio User Manual is available online here. They will help you to familiarize yourself with the various parts of the IDE. For those who are interested, a guided tour around the IntelliJ IDE user interface (on which the Android Studio is based) is also available here. Take some time to familiarize yourself with the functions of the various components of the IDE. For those of you who are familiar with a programming IDE, you can safely disregard this note and proceed with the 'how-to'.
Note that this window shows the source for the package 'MyActivity' Java class. Click on the 'activity_my.xml' tab and the screen as 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.
If any error occurs during the project build, Android Studio will display the error message and will offer a 'Tip' to try out ways of solving it.
Notice that the graphics shown is a Nexus 4 device. If this is acceptable to you, then don't change anything. However, since the author has a Nexus 5X device, it was decided to change the graphics to show such a device. This can be achieved by simply clicking on the downward pointing arrow beside 'Nexus 4', and then selecting 'Nexus 5X' from the drop-down list. Of course, you are free to choose any other Android device from the list depending on the actual device in your possession. Note that there will be no change in the graphics shown (see below) since the 'Nexus 4' device is similar to that of 'Nexus 5X'.
Now that we have created a new 'Hello World' project, we will test it out to see whether it will run as advertised. Before we do this, we need to create either an emulated Android device or use an actual Android device. We will now create an emulated Android device for testing the project. Later, this 'how-to' will describe the procedure for running the project on an actual Android device.
STEP 4: Create a New Emulated Android Device
If you have closed Android Studio, launch it again and make sure that the 'Hello World' project is on the screen. Notice in Android Studio's toolbar an icon with the Android logo on it. Hover the cursor over the icon and you will see 'AVD Manager' - that is the icon I am referring to - then click on it (see below). Alternatively, click on 'Tools' in the menu, followed by a click on 'AVD Manager' item.
No matter which path you took to activate the AVD manager, the window will change to 'Your Virtual Devices' as shown below. If you are running Android Studio for the first time, no virtual devices have been set up and the '+ Create Virtual Devices...' button will be shown. Note the message about 'Android Dashboards' at the bottom of the screen. You can click on this URL to get up-to-date information on the active Android ecosystems. Then click on the '+ Create Virtual Devices...' button.
The 'Select Hardware' window will appear next (see below). It already preselects the Nexus 5X device (you may have to scroll up a bit) with the specifications shown. You are free to select any device listed in the 'Category' section but for the time being keep it in the 'Phone' section.
The screen will also show the size, resolution, and density of each device in the list.
Note the 3 buttons at the bottom of the screen. The 'Hardware Profile' button allows you to create an Android device other than that in the list.
The 'Import Hardware Profiles' allows you to import a profile stored on your computer into Android Studio.
The 'Clone Device...' button allows you the clone the currently selected device (the Nexus 5X in this case), and use this as a base for a new device similar to the Nexus 5X.
For the time being, do not press any of the 3 buttons - instead just press the 'Next' button to proceed.
The next screen is where you specify the 'System Image' to use for the AVD. The 'Recommended' tab is already selected and the cursor is already resting on 'P' item.
NOTE: You may see an error message that says '/dev/kvm device: permission denied' in the recommendation section. This issue was discussed earlier in this 'how-to' plus a possible solution to solve this problem - have you carried this out?
Note the message that 'We recommend these Google Play images because this device is compatible with Google Play' on the right. Since both Android P and Oreo are Google Play devices, we have met this recommendation.
Note that the other item is labeled 'Oreo' and 'Nougat' and you are required to download this items before use.
As mentioned previously, the author has Android 5X device and the system image recommended meets the requirement since that device is running Android 8.1 (Oreo). Hence, this item was selected from the list (see below).
Note that there 2 other tabs for the window - the 'x86 Images' and the 'Other Images' tabs. These allow you to select other images to use (you have to download and install some of these before they can be used). Click on the 'x86 Images' tab and the screen will change as shown below.
If you are unsure which system image to use, click on the link that says 'API level distribution chart'. A distribution chart will be displayed to guide you in selecting the right image to use (see below). When finished with the chart, click on 'Close' to dismiss the chart window.
If you click on the 'Other Images' tab, you will see a window similar to the one shown below. Note the warning message at the bottom of this window. It says that 'A system image must be selected to continue' - since you have not made a selection yet, you can safely ignore this warning. There is also another warning message (in red color) in the right panel of this window - it reads 'Consider using an x86 system image on an x86 host for better emulation performance' - since you have not made a selection yet, you can safely ignore this warning also.
Now click on the 'Recommended' tab and make sure that your cursor is on the 'Oreo' item, then click on the 'Next' button.
You can also click on the 'Show Advanced Settings' button (which will then change to 'Hide Advanced Settings') for more settings to set and configure (see below). This button will reveal the Camera (Front and Back), the Network (Speed and Latency), the multi-core CPU, the Memory and Storage, the Boot Options, and the Keyboard settings. You can change any of these settings if you so wish. Verify all the settings - then click on the 'Finish' button.
You will be back at the 'Your Virtual Device' window (see below) with the newly-created AVD listed as shown. From the icons in the 'Actions' column, you can either launch the AVD (using the right-pointing arrow), edit any AVD settings (using the 'pencil' icon) and perform any other actions (using the down arrow) by clicking on any icons in that column. You can also define a new AVD by clicking on the '+ Create Virtual Device...' button. For now, close this window using the 'x' on the top right-hand of the window and you be back at the project window.
STEP 5: Running The Project On The Emulated Target Android Device
On the Android Studio project screen's tool-bar, there will be a green-colored icon that looks like a right pointing arrow (see below). If you hover your cursor over the icon, the words 'Run 'app' (^R)' button will appear.
Click on the icon (or press the ^R keys) and the 'Select Deployment Target' screen will appear (see below). Note the warning message 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.
Note that the Nexus 5X emulator has been preselected by default. Also, note you can create a new virtual device by clicking on the appropriate button. If you want to use the same device in future, place a check mark in the 'Use same selection for future launches' item in the bottom of the screen.
Now select the AVD that you have just created and then click on the 'OK' button.
NOTE: If you don't see your device, click on the message that says 'Don't see your device?' and the web browser will be launched showing a page from the User Guide on this subject - pursue this page to solve the problem. Close the web browser when done.
The Nexus 5X AVD will start, and after a while, the AVD will appear displaying a flashing animation followed by a 'Google' sign. Then the AVD will display the home screen for a short while, after which the 'Hello World!' words 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 of three horizontal dots - clicking on this will bring up another screen (shown below) where more extended controls are located. You can play with the controls if you wish - when done, close this screen by clicking on the 'x' on the top right.
NOTE: The extended controls allow you to set several parameters such as Location (GPS), Cellular network, Battery level, Phone/SMS calls, Directional pad (useful on a tablet), a Microphone device, Fingerprint device, Virtual sensors (accelerometers, etc), Bug reports, Record screen, Google Play, Settings, and lastly, Help. Since the highlight is on the 'Location' item, you should see the GPS data in the right side of the screen.
To close the AVD, click on the exit (looks like an 'x') button located on top of the control screen. You will be back at the project screen.
NOTE: You may see a red colored error message balloon (labeled 'Event Log') at the bottom of Android Studio's IDE - this will indicate any errors that may occur during the building of the application. If such errors occurs, click on the 'Event Log' and the errors will be listed at the bottom of the IDE as shown below.
Note that you cannot do anything about some of the errors and they will remain listed until Google address the issues. However the last line of the screen will state whether your AVD has been successful - if it does, it should state '<time> Emulator: Process finished with exit code 0'.
When done viewing the error messages, use the 'Hide' button (as shown by the red arrow in the figure above) to hide the screen.
You can close the 'Hello World' project any time by clicking on 'File' menu and selecting 'Close Project'. You will find yourself back at the welcome screen of Android Studio.
Note that the 'Hello World' project appears in the welcome screen - all you need to do to reload or restart the same project, is to click on the project name in the screen. You will see the projects appear in the IDE as shown in the figure below.
Alternatively, if you want to keep the 'Hello World' project (or any project) in the project screen on the next restart of Android Studio, all you need to do is to click on 'Android Studio' in the menu, and select 'Quit Android Studio' item. You need to confirm this exit by clicking on the 'Exit' button.
You can also click on the 'x' on the top left-hand of the project screen and confirm that you want to exit. You will find yourself back at the welcome screen of Android Studio. Then you can close Android Studio if you wish.
STEP 6: Running The Project On An Actual Target 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 smartphone, for example). In order to do this, you need to connect that device to your development PC (the Ubuntu 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. The newer Android devices with Oreo (Android 8.1) has 'Developer options' under 'Settings' -> 'System' but is initially hidden. To reveal this 'Developer options' you need to follow the steps outlined below.
- Tap 'Settings' followed by 'System' and at the bottom, you will find an 'About phone' item.
- Tap on it and scroll to the bottom, where you will find an item labeled 'Build number'.
- Tap on this item 7 times and you will see the message 'You are now a developer'.
- Now go back to the previous screen where you will find the 'Developer options'.
The screen shot shown below is the already revealed 'Developer options' for the Nexus 5X and show that the USB debugging switch has been set to 'On'.
The screen shot below it shows the message that pops up in the smart phone asking you to verify USB debugging by clicking on 'OK'.
If you find an item labelled 'Revoke USB debugging authorizations' on your Android device, tap on that.
A message will pop up and ask you for confirmation. Then clear all previous authorization by selecting 'OK'.
Now click the Android device 'Back' button to exit the 'Developer options', 'System', and 'Settings'.
Now check if you had previously run/installed the same 'Hello World' application on the Android smartphone. This can be done by pressing the 'App' button on the 'Home' screen of the smartphone (the middle lower button that looks like a round button with two rows of 3 dots on it), and then searching for it on the 'App' screen - delete it if found. Then close the 'App' screen - you should be back at the 'Home' screen.
Next, we have to make sure that the proper USB cable is used. The manufacturers of your Android device usually provide you with one - use that cable and none other. Unfortunately, the author's Nexus 5X smartphone comes only with type C USB connectors at both ends so it would be impossible to make connections to an Ubuntu PC with type A USB connectors. Should this be the case with your Android smartphone and your Ubuntu PC, it would mean getting another USB cable for the connection between your Android smartphone and your Ubuntu PC. Purchase one with a type A USB connector on one end and a type C USB connector at the other end.
You also have to make sure that the USB port to be used on your Ubuntu PC is working. Test this port out first by plugging in a thumb drive (or any other USB device) and if the Ubuntu PC recognizes 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 smartphone to your Ubuntu PC using the USB cable. You will note the connection is valid by the figure (as pointed out by the red arrow below) on your Android smartphone Home screen. By the way, the screenshot below shows the author's phone - yours may look different but the valid figure should remain the same.
Make sure that you have configured the USB connection as for transferring files (or photos), and not for charging the battery. This is easily done by swiping down the round figure on your Home screen (see figure above) on your Android smartphone Home screen. Tap on the 'USB charging this device' item and the figure as shown below should appear on the smartphone. Select 'Transfer files' or 'Transfer photos (PTP)' and the screen should disappear.
Then click on the 'Run' button in Android Studio's PC tool-bar. As usual, the 'Select Deployment Target' screen will pop up as shown below.
NOTE: If this is the first time you are using Android Studio, you may see the connected Android smartphone as a string of garbage letters and numbers before you authorize the RSA key (see below) - this is normal for Android Studio, so don't be alarmed. Only after you have OK'ed the RSA key, you will find the 'LGE Nexus 5X' as shown in the figure below, replacing the letters and numbers.
You will also need to authorize the USB debugging connection to the smart phone with the Ubuntu PC's RSA key by selecting 'OK' on your smart phone (see below).
Then, make sure that the 'LGE Nexus 5X (Android 8.1.0, API 27)' item is selected on the 'Select Deployment Target' screen on the Ubuntu PC. 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).
NOTE: You may get a message on your Ubuntu on the existence of a previous 'Hello World' (created by another Android Studio) file installed on your smartphone If this is the case, all you have to do is to press the 'OK' button and it will delete the file for you and you hopefully will see the 'Hello World' message on your smartphone.
If not, see if there are any messages on your Android Studio event log screen of your Ubuntu 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 remember 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 for 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 smartphone first and then switch off USB debugging from the phone.
You should see the projects screen on your Ubuntu PC. To close the 'Hello World' project on your Ubuntu PC, click on 'File' and the 'Close Project' menu items on Android Studio. You will be back to the welcome screen (see below).
Updating Android Studio
If you start Android Studio and see an extra item on the last line, listed as 'Events' on a green background, then it is time to apply updates. Note that the update notifications may appear on the welcome screen or the projects window.
Note that there are two types of updates - one is to the Android Studio itself (and indirectly, IntelliJ) and the other is to the SDK. One would require a restart to Android Studio and the other do not.
To apply the updates, just follow the steps below:
- First click on the 'Events' item followed by a click on the 'update' item.
- Then click on the 'Update and Restart' or the 'Update Now' button and the update process will start. Next, a patch file will be downloaded and installed.
- If required, the 'License Agreement' and the 'Component Installer' will appear next, where the update files are downloaded and installed.
- If you apply the first type of update, Android Studio will be restarted while the second type of update will display the welcome screen again. Note that in either case, there will be the absence of the 'Event' balloon denoting that all updates were applied.
Summary Of Steps
- Download and install Google's Android Studio.
- Configure SDK for Google's Android Studio.
- Create a new project on Google's Android Studio.
- Run the new project on the AVD to test it.
- Run the same project on an actual Android device.
Final Words
That's it. You now have a Ubuntu PC which can be used to develop Android software. What was outlined in this 'how-to' is only the 'tip-of-the-iceberg' - there are more, lots more that you need to discover and learn!
If you are an experienced IntelliJ, Android Studio, Java, and Android programmer, enjoy! For those people who are 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 how to use Android Studio for developing Android software, visit here for a tutorial on this. To read the User Guide for Android Studio, visit here for this. No matter how experienced you are, I urge you to read this manual.
To learn about the IntelliJ IDE (on which the Android Studio is based), visit here 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, 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'.
Happy computing!