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 2 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.
- [Voiceover] 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 three and then the subfolder 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 dot, slash, 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 forward slash 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 sign 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 AndroidManifest 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 AndroidStudioProjects 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'll 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 of 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 import-summary.txt, 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 clean 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 debugged 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