Sunday, April 29, 2018

How to Install Android Studio on a macOS High Sierra

This article is for installing and using Google's Android Studio on a 64-bit macOS High Sierra computer. If you wish to develop software on the Android platform on your Mac, then this 'how-to' is for you. Note that the version numbers are deliberately left out (unless mentioned) for the Mac and Android Studio. This means that this 'how-to' can apply to (almost) any version - unless a specific change has occurred.

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 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.

Please note that OpenJDK is now officially supplied with Android Studio and there is no need to install Oracle's Java JDK on the Mac. If you are new to Java, then I suggest you download and install the OpenJDK JDK and a Java IDE (e.g. IntelliJ, Eclipse, etc).


STEP 1: Install Google's Android Studio


Start a web browser (e.g., Safari) and type 'download android studio' into the search box and press the 'Return' key. Then click on the first or second item in the search result and the web page as shown below will appear.


Click on the big green button that says 'DOWNLOAD ANDROID STUDIO' and then agree to the terms on the next window. Then click on the big blue button to start the download.


The instructions for installing Android Studio will appear on the web browser - take time to read it.


Wait for the downloads to finish, then close the web browser.

Open the Finder and you will find the downloaded file in the 'Downloads' folder. The name (as of April 2018) of the file is 'android-studio-ide-173.4697961-mac.dmg'. Note that the file name may change as Google is constantly updating it.


To install Google's Android Studio on your Mac computer, double click on the file name in Finder and you will find a .dmg file on your desktop, plus the image shown in the figure below.


According to the image, you need to move Android Studio into your 'Applications' folder of your Mac computer - do so and Finder will move that file into the destination folder. Wait for the process to finish, then you can now safely close the image and eject the .dmg file from your desktop. Now open a Finder and locate the icon for Android Studio.

To start Android Studio for the first time, double-click on that icon in the Finder's applications window. You will see a warning from the Mac computer as shown below.


Click the 'Open' button and the window as shown below will appear. This first window asks whether you want to import any settings. If this is the first time you installed and started Android Studio, chances are that you don't have any - so just click on the 'OK' button. Of course, if you had installed Android Studio on Eclipse previously and wish to preserve the settings on Eclipse, feel free to import the previous settings.


Android Studio will begin loading as shown in the figure below.


The Setup Wizard for Android Studio will start and the first window (the Welcome window) will look like the one shown in the figure below. Click on the 'Next' button to proceed


The Install Type window will appear next as shown below. The 'Standard' type of setup is already preselected - unless you have a need to customize the setup, click on the 'Next' button.


The Select UI Theme window will appear next (see below). Select the User Interface (UI) theme of your choice (the Default theme was selected in this example) and then click the 'Next' button.


The Verify Settings window will appear next as shown below. If you need to change anything, click on the 'Previous' button - else click on the 'Finish' button.


The Downloading Components window will appear next as shown below. If components need to be downloaded and installed, Android Studio will do so.


If a window appears while installing the Intel x86 Emulator Accelerator or HAXM (see below), enter your password to authorize the installation.


When finished, it will display a message 'Android SDK is up to date' (where SDK stands for Software Development Kit) as shown in the figure below. Click on the 'Finish' button to close the Setup Wizard.


Android Studio will start and the welcome screen will appear as shown below.


Note that the initial IDE contains several 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, and exporting/importing a project. There are 2 other items found on the initial IDE - one is for configuring the IDE and the other one is for seeking help. For this 'how-to', only the first item 'Start a new Android Studio project' on the list, 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 version. One of the major differences is the way Android Studio handle updates - if there are any, a line will appear on the IDE window which will contain an additional item - the 'Events' item with a green balloon to the left. Click on the 'Events' item and follow the on-screen instructions if you wish to apply the updates.



STEP 2: Configuring SDK Manager


On the welcome screen of the main Android Studio IDE, click on 'Configure' and the 'SDK Manager' item (see below).


The Default Preferences window will appear as shown below. Note that this window will show all the possible Android versions (so far), back to version 2.1 - the version with the name Eclair. It will also list their API level, revision number, and status (whether it is already installed or not). Make sure you read the note below the tabs.


Note that the 'Android SDK' item is automatically selected in the right pane of this window. Other items are listed and available, but for the time being, let us concentrate on the Android SDK only.

The column to note is the 'Status' column - it is where the window indicates whether the package has been completely or partially installed. For the purpose of this article, a 'package' can include other packages - but this window will only show the 'main' package.

The location of the Android SDK is clearly stated on this window, and you can change its location if you wish - but for the purpose of this article, keep it as it is. Note that the default location is usually '/Users/<user-name>/Library/Android/sdk' where '<user-name>' is your login name.

Note also that the tab below the location of the Android SDK (as stated above) is 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 the item 'Intel x86 Emulator Accelerator (HAXM Installer)' which is marked as 'Installed'. Make sure that this item exists and is installed on a Mac computer - else you may experience problems with the emulator later.



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 by default. You are free to install any other extra tools as you so wish.


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 window 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 moment it is not selected (i.e., no check mark has been placed there). Click on that button to select it and the display window will show more details on the packages installed so far - note the names assigned to each item. This will give us some clue or purpose for that package.

Based on your requirements, you may decide to install more packages beside Android P Preview - for example, the author has a Google/LG Nexus 5X smartphone running on Android 8.1.0 (Oreo) - so it was decided to install the additional packages as shown by selecting the radio buttons next to its names. Note the 'download' icons that appear as soon as you select the radio buttons for the items (see below).


NOTE: If you decide to use the latest Android P, do so as the latest Android version is backward compatible.


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.



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 Intel HAXM virtual machine 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.



The display will change to the one shown below. Click on the 'OK' button to confirm the changes.


The display will change to the one shown below. Click on the 'License' for each item to download, then the 'Accept' button, followed by a click on the 'Next' button (see below).


The screen (the Component Installer) as shown below will appear next and download of the components will start.


Wait for the download to finish. Note that, should any file failed to download, it will be shown on the window. Try downloading the file(s) again. Then press the 'Finish' button (see below).


You will be back at the Default Preferences window of the Android SDK (see below). Inspect the packages that were downloaded and installed to make sure that they are correct, then click the 'OK' button.


You will be back at the welcome window of Android Studio. Before you do anything else, you need to place a launcher for Android Studio in your Mac dock in order to make it easier to start it. Right-click on the 'Android Studio' icon (see figure below), then click on 'Options' item. Then you can pin 'Android Studio' to the dock by clicking on the 'Keep in Dock' item. Now all you need to do later is to click on the 'Android Studio' icon in the dock to launch the application, instead of having to open Finder, select Applications and then double click on the 'Android Studio' icon. You can go ahead to test this launcher but remember to close the currently running copy of 'Android Studio' first.



STEP 4: Create a New Project Using Android Studio


Now that you have successfully configured Google's Android Studio, 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 Device (AVD), or your actual Android device.

Use the icon in your dock to launch Android Studio if it is closed. Start a new project by clicking on the 'Start a new Android Studio project' item (as shown by the red arrow) from the welcome window (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 'any.company.com' as shown. The directory in which this project reside can be anywhere on your computer. In the example shown, the project was placed in the author's '/Projects/Android/HelloWorld' 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 window - but I suggest that you keep this package name - at least for this 'how-to'. Likewise, you can also enable C++ and Kotlin support by enabling the appropriate box - but for this 'how-to', leave it off. For details of these 2 support, consult the Internet.


The 'Target Android Devices' window 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 'how-to', leave it at the preselected minimum SDK. Do not select any other items. Then click on the 'Next' button.



NOTE: You can enable 'Android Instant Apps support' by clicking on that item in the window. It will allow Android users to run the apps instantly, without installation. Leave it off for this 'how-to'.

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 app. 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.

Android Things is an Android-based embedded operating system platform. It is aimed to be used with low-power and memory constrained Internet of Things (IoT) devices.

Note that to enable your app for Android Wear/TV, your app must target Android 5.0 (API level 21) or higher, while Android Auto/Things must target Android 7.0 (API level 24) or higher.



The 'Add an activity to Mobile' window 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' window will appear next (see below). Change the 'Activity Name' to 'MyActivity' and the rest of the items below will change as shown - this serves to illustrate the interactions between these two items. Then click on the 'Next'/'Finish' button.



NOTE: There are two other 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' window may appear next if Android Studio requires a downloading and installing of requested SDK components. When all the components have been downloaded and installed, click on the 'Finish' button.


Android Studio (the 'Gradle' part anyway) will then start building the project as shown below - this initially 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 project in the Android Studio IDE.

When 'Gradle' is finished, Android Studio will display its main IDE window (see below).


If a 'Tip of the Day' window appears (also shown below), 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 on-line 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'.



The main window will display whenever you have a project open in it. Note the tabs at the top of the editor - they are labeled 'MyActivity.java' and 'activity_my.xml'. Currently, the 'MyActivity.java' tab contents are being displayed. To display the contents of the 'activity_my.xml' tab, just click on that tab and the contents will display as shown below.


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 (see below).


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 since the 'Nexus 4' device is similar to that of 'Nexus 5X'.

If you see the figure 'P' next to the newly-set 'Nexus 5X', then change it to say '27' by clicking on it and selecting '27' in the drop-down window (shown below). This is to cater for the Nexus 5X device that the author has.


Alternatively, you can also leave it at that preselected API level - Android P (this is shown as 'Automatically Pick Best' in the figure below).


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 article will describe the procedure for running the project on an actual Android device.


STEP 5: Create Emulated Target Android Device


Notice in Android Studio's tool-bar an icon with some words in it. Hover the cursor over the icon and you will see 'AVD Manager' - that is the icon the author is referring to - then click on it (see below).


Alternatively, click on 'Tools' in the menu, followed by a click on 'AVD Manager' (see below).


No matter which path you took to activate the AVD manager, the window will change to 'Your Virtual Devices' as shown below.

Note the message about the 'Android Dashboards' - should you click on this, you will be shown a web page indicating which Android device has the largest market share - close this page when done.

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. Click on that button.


The 'Select Hardware' window will appear next (see below). It already preselects the Nexus 5X phone device with the specifications shown. Note that there are other categories of items that you can choose from - but for this 'how-to' let it remain in the 'phone' category.

Note the 3 buttons at the bottom of the screen. The 'Hardware Profile' button allows you to create an Android device other than that on 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 (see below). The 'Recommended' tab is already selected and the cursor is already resting on 'P' item. Also, note the message that 'We recommend these Google Play images because this device is compatible with Google Play' on the right.


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. When finished, click on 'Close' button to the window.


As mentioned previously, the author has Android 5X device running Oreo (API 27)) and so, it was decided to change the system image to Oreo which meets the requirements. Move the cursor to the "Oreo' entry.

Note that there other tabs - 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 below will appear - if required, make your selection.


Click on the 'Other Images' tab and the screen below will appear (see figure below). Note the warning message at the bottom of the window and the 'Recommendation' section (in red) - you can ignore them if you already made your selection. If need be, make your selection and click the 'Next' button.


The 'Android Virtual Device (AVD)' window will appear next (see below). Note that you can change (if you wish) some things on the window. For example, if you wish to change the name of the AVD all you have to do is to click anywhere on the field and make the changes. You can also change the AVD device and/or the Android OS by clicking on the 'Change' button. The Startup Orientation is also changeable - portrait or landscape mode. Likewise the Device Frame.


You can also click on the 'Show Advanced Settings' button for more settings to set and configure. This button will reveal the Camera (Front and Back), the Network (Speed and Latency), the Emulated Performance (Graphics, Boot Options and Multi-Core CPU), the Memory and Storage (RAM, VM heap, Internal Storage, SD card), the Device Frame, Custom skin definition (click on the URL shown if you want help on this), 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 here, you can either launch the AVD (the right-pointing arrow icon), edit any AVD settings (the pencil icon) and perform any other actions (the downward pointing arrow icon) by clicking on any icons in the 'Actions' 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 left-hand corner, and you be back at the project window.



STEP 6: Running The Project On The Emulated Target Android Device


On the Android Studio project window's toolbar, 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' window 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. 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 Safari 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 by displaying a small 'Android Emulator' window, 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. 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 window (shown below) where more extended controls are located. You can play with the controls if you wish - when done, close this window.



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.


To close the AVD, click on the exit button located on top of the control window. 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 (see below) - 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 window 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 window.



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 window of Android Studio.


Note that the 'Hello World' project appears on the welcome window - all you need to do to reload or restart the same project, is to click on the project name in the window. 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 window 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 window. You will find yourself back at the welcome window of Android Studio. Then you can close Android Studio if you wish.


STEP 7: 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 smart phone, for example). In order to do this, you need to connect that device to your development computer (the Mac computer 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.
  1. Tap 'Settings' followed by 'System' and at the bottom, you will find an 'About phone' item.

  2. Tap on it and scroll to the bottom, where you will find an item labeled 'Build number'.

  3. Tap on this item 7 times and you will see the message 'You are now a developer'.

  4. Now go back to the previous screen where you will find the 'Developer options'.
If unsure on this process, consult your 'User's Manual' or the manufacturer's web page for the information on how to enable USB debugging. In any case, Google has the same steps on-line here.

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 labeled '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 smart phone. This can be done by pressing the 'App' button on the 'Home' screen of the smart phone (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 smart phone comes only with type C USB connectors at both ends, so it would be impossible to make connections to a Mac computer with type A USB connectors. Should this be the case with your Android smart phone and your Mac computer, it would mean getting another USB cable for the connection between your Android smart phone and your Mac computer. 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 Mac computer is working. Test this port out first by plugging in a thumb drive (or any other USB device) and if the Mac computer 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 smart phone to your Mac computer 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 smart phone Home screen.


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 smart phone Home screen. Tap on the 'USB charging this device' item and the figure as shown below should appear on the smart phone. Select 'Transfer files' or 'Transfer photos (PTP)' and the screen should disappear.


Then click on the 'Run' button in Android Studio's computer tool-bar. As usual, the 'Select Deployment Target' window will pop up as shown below.


NOTE: If this is the first time you are using Android Studio, you may see the connected Android smart phone 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 Mac computer'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' window on the Mac computer. 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 Mac on the existence of a previous 'Hello World' (created by another Android Studio) file installed on your smart phone 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 smart phone.


If not, see if there are any messages on your Android Studio event log screen of your Mac computer. 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 smart phone first and then switch off USB debugging from the phone.


You should see the projects screen on your Mac computer. To close the 'Hello World' project on your Mac computer, click on 'File' and the 'Close Project' menu items on Android Studio. You will be back to the welcome screen.



Updating Android Studio


If you start Android Studio and see an extra item on the last line, listed as 'Events' (indicated by the red arrow in the figure below), then it is time to apply updates. Below are some example screen shots of this process - these are examples only and may not reflect on what you see on the screen exactly. Note that the update notifications may appear on your welcome screen or your 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. The example shown for the first is an illustration for updating Android Studio 3.1.1.

If you see the window with the green-colored 'Event' balloon, first click on the 'Events' item followed by a click on the 'update' item as shown below.


Then click on the 'Update and Restart' button (see below) and the update process will start.


Next, the patch file will be downloaded and installed as shown in the figure below.


When done, Android Studio will be restarted and the figure below will be shown. Notice that there is no more 'Events' item. You are done updating Android Studio itself.


Final Words


That's it. You now have a Mac computer 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!

No comments:

Post a Comment