Finding your way around Android Studio Android development has become a lot more beginner friendly over the years thanks to constant improvements and iterations from Google. But with that said, booting up Android Studio for the first time is still a less than welcoming experience and it can be more than a little confusing at first.
But don’t worry, it all makes sense once you get stuck in and with a little guidance, you’ll be a pro in no time. So open up the IDE and let’s begin the guided tour.
Navigating the UI
You might be feeling a little daunted at this point. There are a whole lot of windows, icons and menu options which can all feel a bit like sensory overload.
The good news is that you don’t need to know what everything does just yet and the easiest way to learn is to encounter each button and option as you need it.
Let’s start with the absolute basics. You have the source code on your right in the largest window. Whichever file you’ve selected will be the one that shows here. If you look just above the window you’ll see a tab, which will likely say ‘MainActivity.java’. This means that the file you’re currently looking at and editing is the MainActivity.java file – the default first piece of code that loads when your app runs. Above that is the route of the file. This is probably:
App Name > App > Src > Main > Java > Package Name > App Name > MainActivity
Note that you can have more than one file open at a time and then switch between them by hitting the tabs along the top. You probably have two files open already in fact: activity_main.xml and MainActivity.java. You can try switching between these, if you so wish.
Over on the left, you have a hierarchy. This is your project structure and basically acts like a file explorer to show you all of the files that are involved in your project. If you were to select another activity, a class or a layout file, then it would open up in the big window on the right.
inally, down the bottom you will have another window where you can see messages, a terminal, an Android Monitor and more. The window may be minimized at the moment but if you click on any of these bottom options, it will pop up.
This window is what you will use for debugging your app.
Files and project structure
One of the things that confused me most when I started with Android development for the first time, was discovering at there was such a range of different files that made up a single app. If you have any background in other types of programming, then you might be used to creating a single file and then hitting ‘Run’ to test it out. Here though, we have our activities, layout files, resource files, manifest, Gradle scripts… it’s all a bit confusing.
But if we break it down, then it doesn’t have to be quite so intimidating.
The main part of your app you need to keep in mind is ‘MainActivity.java’. This is the code for the first activity: the first screen of your app. This is what will handle the logic of button presses and it’s where you’ll write code to handle specific functions; if you want to make the phone vibrate for example.
You’ll find this in the left window by navigating to:
app > java > package name > MainActivity.java
The second important part of the app is the ‘activity_main.xml’ file. This is the layout file, meaning that it will handle the design and the appearance of your app. This is where we’ll add buttons for instance. You’ll find it under:
app > res > layout > activity_main.xml
If you have another look at MainActivity.java, then you’ll notice that there’s a line that says:
This is telling us that the appearance for that activity is located in resources > layout and is called activity_main. We could change this to any other XML file if we wished.
Also in the ‘res’ directory is a folder called ‘drawable’. This is where you’ll place any images you want to reference later on. In ‘values’ you have some more xml files called:
These store values for your colors, for text that will populate your apps etc. meaning you can reference them from any other application. The mipmap folder is where you’ll put the icon for your image.
We’ll discuss this more in future.
Another important file is:
app > manifests > AndroidManifest.xml
This is a file that contains crucial information about your app. This is where you can change things like your app’s name, the version of Android you want to target and the permissions that it will require.
Finally, Gradle is a ‘build automation system’. This is used to index all the files used in your app and to build that final APK when you’re ready to run or distribute your app. It’s also where you will add ‘dependencies’, which means you can use libraries that offer additional functionality for your code. You can pretty much just leave Gradle to do its thing 90% of the time. That said, you might find that you see notes that say things like ‘Gradle build finished’ – so now you know what that’s talking about.
Every now and then, Gradle can get a little confused or it might not successfully update all the files in your app. If this happens and your app refuses to run when really it should, try selecting:
Build > Clean Project
That will often solve the problem. Otherwise, you can ignore Gradle until you want to start doing fancy stuff with libraries and instant apps. That won’t come until much later in your journey as a developer.
For the most part, you don’t need to worry too much about these other files for now. Understanding the structure of your app and knowing what all the files do will help to prevent confusion though and I think it’s always important that you know what all the code you’re writing is actually doing and how it relates to other aspects of your project.
But I know you’re itching to get started and to make something that actually runs, so that’s precisely what we’ll be doing in the next post!