Hello and welcome back. May name is Jay, and I am your
trainer for today. We are going to assume that you already went through Episode
1 to 3. Now, it’s time to build that hello world project.
We are jumping into development now. That means, the page
will be heavy with screenshots. I have tried my best to use low sized images so
that you can load this even on a 2G connection. If you are having issues
loading any of our tutorial pages, contact us. You will find the contact
information, at the end of the blog.
You can download the code for this project, from GitHub,
right here – https://github.com/Jay-study-nildana/helloworld2
If you don’t know about GitHub, check out our blog post here
Here is what you will see when you run Android Studio for
the very first. Select the option that is selected in the blue circle. This
will create a new project for you.
The next image you will see will be something like this
So, there are three parts here
- Application Name – This is where you get to
choose your project name. You can give any project name you want. The example
names are – ‘HelloWorld’ or ‘helloworld’. If you try to start your project name
with a lower case or small letter such as ‘a’ or ‘b’, Android Studio will give
a warning. You can safely ignore that, and your project won’t be affected in
- Company Domain – This part always confuses
people. The thing, you don’t need to have a website or any ‘domains’ to write
here. You can write any company domain you want. For example, if your favorite
hero is Shahrukh Khan, you can write the domain as com.srk.apps or srk.apps or
apps.srk.com. Just remember that the domain name you use, will eventually show
up when you publish in the app store. So, ensure that you choose a domain name
that looks cool and simple. In our photo, we are selecting
‘com.studynildana.apps’ and as a general practice, we use the exact same domain
for all our apps.
- Project location – This is where your project
will be store. You see that folder called “AndroidStudioProjects”? That is
where you can copy paste our project folder and run it. Same works for any
project that you get from the internet. Just put the project folder into this
‘AndroidStudioProjects’ and then open it from Android Studio.
Here is the same photo, but with the ‘Hello World’ project
and study nildana domain and project location. Note that red error at the
bottom. That is coming because I am using lower case letters for the app name.
I am going to ignore that error. If you are bothered by that error, please use
‘Hello World’ as the project name instead of ‘hello world’ as I have done.
Now, click next and you will see something like this.
The circled part is the ‘Minimum SDK’ and I have chosen
API16 that is connected to the 4.1 version of the Android OS. Someday, I might
write up a post why you should choose what version. For now, understand this.
Choose Android 4.1 (API 16), so that most of your friends can install and run
the app you are about to build. The other options – Wear, TV, Android Auto –
should be left alone. We are not focusing on building the app to run on
watchers or television or cars. Someday, when you start building apps for these
devices, you will check those boxes.
Next, you will see this window where you select an activity.
Write now, we are building a simple activity. In a future
post, you will learn more about Activities. For now, go with the blank
And then, you will see this image. Leave everything as it
is, and click Finish.
The project will be created and you will see something like
this and you are ready to go.
…and this is where your first project
Oookay, this one is big. Let me go through all the 8 points.
Menu – This is the menu. Here you will be using the following a lot – File (for opening and creating projects), Build (for building the app and also generating the APKs) and Run (configuring the emulator and other stuff). Most of the time, you will be using File and Build.
- Project Structure – This is your app structure. This is where all the files of your app are shown in a tree form. You can change the view of this structure by using the option on the top left corner of that circle. The selected view in the photo above is ‘android’.
- Widgets – These are standard readymade widgets (things like button, text input and output) that are available for you to drag and drop into the Layout (pictured as number 4 in the image)
- Design Preview – This is where you get to design your app. Drag and drop things and select widgets. As seen in the picture, you might get a “Rendering” related error. Don’t worry about it. This happens with Android Studio, quite often. Just wait it out, and it will go away. Also, there is are two options – Design/Text – at the bottom right corner of the Design Preview. You can use that to toggle between the design view and the text view. The text view gives you XML code (sort of like HTML). Again, we will use it later.
- Component Tree – Use this to see how your layout is nestled. Also, use this to directly select the widgets that are placed on the UI (in the Design Preview).
- Properties – This is where you will be able to select the properties of the UI element you have placed. Mostly use it for changing the ID, set the width, height, text and similar properties.
- Indexing or status bar – This is your best friend, because you will be looking at this spot a lot of times. You see Android Studio does a lot of things (Only god knows why!) and is constantly doing stuff. This slows down (I have mentioned Android related slowness before) everything but you have no escape from this. The only advice I can give is, always wait for the status bar to become clear before you do anything. Of course, if you have a computer that has like 16 GB RAM or something, you don’t have to worry about it. Then again, if you could afford a 16 GB RAM computer, you won’t be reading this tutorial now would you?
- Terminal, Output, Android – This is where you see output from logs. For now, remember that much and keep an eye on this whenever you build the app or run the app. You will discover what this is all about.
Now, we are all up to speed, let’s test if your Android
setup is working. Also, if you notice, the project already has hello world in
it. So, go back to the Menu (one of the 8 things I have marked in the photo), and
select Build. Then, go to ‘Rebuild Project’ and let the IDE do its thing. You
should not be getting any errors, if it is does, you should head over to stack
If everything goes as planned, in the bottom left corner
(item 8 on the photo), you will see something called ‘Gradle build finished’.
‘Gradle’ is the tool used by Android to build everything. Once it has finished,
you will be able to run the app.
Running the app
There are two ways to run the app.
- Using emulator
- Using phone
Running the app – emulator
Android Studio comes with its own emulator which will run if
your computer is powerful enough. That means, it should support virtualization.
Here are some things to remember when trying to get the emulator to work
- If your computer has 2 GB RAM or less, it is definitely not a good idea to use the emulator option.
- Usually, ‘Intel Virtualization’, is disabled on most computers. You will have to enable it in the BIOS.
- After enabling Intel Virtualization, make sure that windows is not using virtualization for its own purpose. In other words, you will have to disable ‘Hyper – V’ on your windows computer.
- Lastly, after doing all this, you may still get an error about virtualization. If so, download and install the latest version of HAXM. It’s an Intel tool that needs to be installed as well.
Finally, after doing all this, the emulator will run. As with the rest of Android Studio, The Android Studio Emulator is like a giant big Ox. It’s slow and will drive you mad with its launch speed and loading intensity. I am not complaining but simply making an observation. I am telling this to you so that you know what you are getting into here.
Look at the menu, and right below ‘Tool’s, you should see a green colored ‘play button’. Press it, and you should be provided with an option to choose a ‘virtual device’. The first time you do it, you will be asked to create a new ‘virtual device’.
Here are some tips when you are creating your ‘virtual device’.
- Select a lower resolution such as 480 X 800 or something similar. A lot of android learners try to create a high resolution virtual device, and that will definitely crash the emulator.
- Select low RAM of 1 GB for your virtual device.
- In general, select the lowest possible configuration and see if it works. Later, as you get used to android studio, you will know which emulator is the best for you. Of course, if you have a 16 GB RAM and above computer, you don’t need to worry about all this.
Here is the welcome screen you will get when you already have created your virtual device.
If everything has gone as planned, you should see something
like this on the bottom left corner.
If you already know some coding, you will notice that there
are some command line arguments for netspeed and netdelay. You will learn those
things later. Finally, after some serious waiting, you will finally see the
emulator running on your PC and it will look like this.
Here are some things you need to remember about the emulator, after it has launched.
- By default, the emulator will take up your entire screen. IT WILL LOOK HUGE!
- Also, it will sit right in the center of the screen. That is weird.
- Even more weird is that, you cannot actually move the emulator away with your mouse. The ‘move’ bar at the top is hidden. To actually move the emulator, you should press and hold SHIFT KEY on the keyboard, and then right click on the emulator on the taskbar (the bar at the bottom of your computer screen). Then, you will get an option to move the emulator and you can finally do that. There, I just saved you so many hours of headache with the huge emulator.
Now, go ahead and unlock the virtual phone with the emulator, and you will see that the app will launch automatically. Sometimes, the app wont launch, in which case, you should simply run the app as described above and it should work.
Finally, here is the default app with Hello World written in it.
Whoa! That was hectic. To keep this post simple, I have
skipped a few things. Nevertheless, if you run into any errors or find that I
have not explained a particular term, stack over flow is your friend.
That takes care of the basic Hello World. In the Episode 5 –
“Hello World – Part 2”, I will modify this project and make it display ‘study
nildana’ on the screen. Further, you will also see how to run it on your phone
instead of the emulator.Follow me on twitter, facebook and instagram for more updates. Thanks!