Whenever possible, I recommend testing your apps with physical devices. You'll get a more realistic sense of how your app will behave in your users’ hands. And there are many things a physical device can do that are difficult to emulate with a virtual device. For most of this course, I'll be demonstrating my sample apps with this Nexus 5X cell phone running Android 7 Nougat. I’m projecting the phone’s screen to my computer’s screen, but it really is an actual phone.
- [Instructor] Throughout most of this course, I'll be using the Android SDK Tools, through Android Studio. The tools can also be called from the command line, and there are times when it's important to know where they are, and how to use them. I've opened up Command Prompt on Windows, and I'm going to my SDK directory. Which I've placed under my Home directory. If you're working on Mac, go to the SDK directory under Library, under your Home directory, and then Android\sdk. Now, I'll type dir, and then asterisks tools.
I see that there are three directories that have the word tools in their names. The build-tools, platform-tools, and then simply tools. The two most important of these are the tools, and the platform-tools directories. I'll list the contents of platform-tools. If you're working on Mac use ls, instead of dir. I'll see that there are commands named adb, dmtracedump, fastboot, and so on. abd is the Android Debug Bridge. A critical piece of software, that let's you communicate with the device when you're running it, as you test your app.
It works with both virtual, and physical devices. There's also an important tool called fastboot, that you'll use when you configure an android device. Now, I'll switch to the tools directory, and list the applications there. There are a variety of applications that start with emulator, and these are the applications that run the android virtual devices. There's also one named mksdcard. Now, I'm mainly concerned with the platform-tools directory, because that's where the adb command is.
I want to be able to run the adb command, from any where on the hard disk, so I need to add this to my path. On Windows, you do this through an environment variable. Start off in your control panel, and then type environment, and click on the link to Edit the System Environment Variables. Then on this dialog, click the Environment Variables button. You can add these directories to the path either in the User Variables, or in the System Variables.
I've added them in my User Variables, and I've already done the work here. Notice that I've added both the tools, and the platform-tools directories to my path. When you're adding these values, make sure you type them exactly correctly. On Windows you separate the directories from each other with semicolons. After you've entered the values, click OK. Click OK again, and click OK again. Then exit any Command Prompts, and start them up again. Then type adb, you should get a listing of all the different commands that are available.
Now, if you can't find the adb command, log out, and then log in again, and that will force the environment variables to take hold. If you have physical devices attached, or virtual devices open on your computer, you can now type adb devices. The first time you run the adb command in any session, you'll get this message saying, that the daemon is starting up. Then you should see the listing of devices. Again, I have a physical device attached, and a virtual device running, so I'm seeing them both listed.
To add the SDK's tools directories to the path on Mac, you can create a file called .bash_profile in your home directory. I've already created this file on my system, but I'll show you how to create it from scratch. Start in a terminal session, and then switch to your home directory, by typing cd, and then the tilde. In order to create this file, use a text editor named nano, that's included with MacOS. Make sure you're working as the superuser.
Type sudo, then nano, and then .bash_profile. Make sure you spell the file name exactly as I'm showing it here. When prompted for your password, type it in, and that will open the nano application. Now, I already have my file on disk, but if you don't, this will create it. Then you want to type in the commands that you see here on screen. They look exactly the same, regardless of how you're logged in, because the tilde character means your home directory.
Again, this assumes that you've installed the SDK in the default location, under your library subdirectory. After you type that value in, press ctrl X, and then if you're prompted to save the file, follow the prompts to do that. When you return back to terminal, you can then type source .bash_profile. That will execute the commands. You only have to do that once, when you first create the file. In the future when you log in, the .bash_profile's commands will be executed automatically.
Now, to see your listing of currently connected devices, type adb devices, just like I did in Windows. On Mac I haven't started up a virtual device, so I'm only seeing the one physical device that I have attached, but it's working exactly the same as before. Notice the word unauthorized. On my physical device I'm now seeing the prompt to allow USB debugging, so I'll touch OK on it, and then I'll run that command again, and this time I see the word device.
That means USB debugging is working, and I'm ready to deploy applications to that device. Again, notice that I don't have to switch to the directory that contains the adb command. By adding these directories to the system path, you have the convenience of being able to run them from wherever you are.
- Installing Android Studio
- Creating your first Android Studio project
- Managing profile files, including Gradle scripts and support libraries
- Defining screens with activities
- Implementing designs in XML layouts