If you’re new to Android Studio, but have been developing Android apps with the command line or other environments, you can import those projects into Android Studio. You'll end up with two different projects: the original version, and a new version that's been reorganized for use in Android Studio. The new version will have some newly created configuration files, and some files and directories from the old version might be left behind.
- [Instructor] This video was recorded when you could still create new Android projects from the command line. The Android command that I've described is no longer available starting with Android Studio 2.3. If you don't already have projects that you created from the command line, you can skip this video. If you're new to Android Studio but have been developing Android apps with the command line or other environments, you can import those projects into Android Studio very easily. I'll show you how to do this with an app that I'll create from scratch from the command line.
You can also use a project that I've included in the exercise files under Chapter 3, and then the sub folder for this video, and the name of the project is CommandLineApp. I'm working on a Mac and so I'm in terminal. If you're in Windows, go to a command prompt, then if you're able to reach your Android tools, you can work from whatever directory you're currently in. I'll type Android and I get the Android SDK Manager. If instead you see that you can't get to the tools, you'll need to switch to your SDK directory.
On Mac that will start with the tilde for your home directory and then the default location is Library/Android/SDK. On Windows, again just locate the correct directory. Then from there switch to the tools directory and look for the Android command. Here's the command to create the project. On Mac I'll start with ./ and then android, and on Windows just type Android.
Then create project. Then I need to pass in a bunch of parameters. First I need to indicate the API level, which is known here as a target. I'll type --target, and then a value of one, which means the first target in my SDK installation. Then --name, and I'll name my project CommandLineApp. Next is the path, the location where you're going to create the project. I'll type --path, and then on Mac I'll start with the tilde and a / for my home directory, and on Windows you'll need to type in the entire home directory location.
Then from there, I'll go to my desktop and then I'll create a new directory on the desktop named CommandLineApp. Next I'll name my default activity, with --activity and I'll name it MainActivity, and then finally, I will assign a unique package for the application. with --package, and then, an application ID, I'll use com.example.android.commandline. And when I press enter or return, that creates the project, and here it is.
A project created from the command line has an ant.properties file to manage the build process, an Android manifest file, a resources folder, and a source folder which contains your Java code. So now I'm done with my terminal window, I'll close that and I'll go to Android Studio's welcome screen. And I'll import a project. Notice the label says I'm importing a project from Eclipse ADT Gradle et cetera, but you can also use this to import a project that was created in the command line environment.
I'll go to my desktop, and I'll refresh the view to make sure that the command line app shows up, and I clicked the refresh button up here on the toolbar. Then I'll select that folder and click OK. Next I'm asked where I want to import the project to. I'll be creating a new version of the project, I won't be overriding the existing one, and I'll place it in the Android Studio Projects directory. On this screen I'm asked whether I want to replace jars and library sources with Gradle dependencies.
I'll describe dependencies in detail later in the course, but essentially they're a simple way to describe in a Gradle build file, which components you want to include as you package your application. I'll leave both of those options checked, and I leave the third option checked as well, and I'll click finish to import the project. It should take just a few moments to import the project, copying all the files from the old location to the new location, and reorganizing everything so that it's compatible with Android Studio.
Each time you do one of these imports you'll get a file named ImportSummary.text, and it'll show you which files were ignored, because they don't make sense in Android Studio, which files were moved around, and other useful information. Now before you try to run this app on a device, you should rebuild it. So I'll go to the menu and choose Build, Clean Project. When you cleaned the project any existing artifacts from the last build are removed and the app is built from scratch.
Then I'll click the Run button. And I'll use my Nexus 5X that I've connected to my computer. That will result in rebuilding the project, creating a debug package, copying it to the device, and then the app will run on your device. And this is what an app looks like when you create the app from scratch in the command line environment. It doesn't look like a modern Android app, but it works. And so, if you're an existing Android developer, and you're coming from command line development, you can move your projects into Android Studio, and then continue on from there, developing and maintaining your app.
- Installing Android Studio on Mac and Windows
- Creating Android Studio projects
- Setting up the development environment, including HAXM and the new Android emulator
- Importing existing code into Android Studio projects
- Exploring the interface, including the editor and project windows
- Managing project builds and dependencies
- Creating new Java classes
- Refactoring code
- Using templates
- Using breakpoints and watch expressions
- Updating apps with Instant Run
- Using Git for version control
Skill Level Beginner
Q: This course was updated on 04/27/2017. What changed?
A: New videos were added that highlight the new features introduced in Android Studio 2.3. In addition, the following topic was updated: update apps with Instant Run.