17

Introduction to Android App Development With Kotlin: Android Studio, New Project...

 5 years ago
source link: https://www.tuicool.com/articles/hit/ZbyE3iR
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

If you’re reading this, I speculate that you are interested in Android app development. This tutorial is the first in the series of tutorials where we’ll go through the basics of Android development. I’m a firm believer that the best way to learn is by doing. So each tutorial will have a list of steps you are expected to follow. If you do, you’ll end up with a working app that can be a backbone of a bigger project. We’ll use the latest version of Kotlin and Android's newest architecture components. We’ll learn about Room, LiveData, and much more.

If you have done Android development in the past, these tutorials are probably not for you. You should read on if:

  • You would like to dive into the wonderful and prosperous world of app development
  • You would like to learn the basics of Android app development
  • You actually want to make an app rather than just read about making one

Lesson 1

You’re still here… Well then, welcome aboard.

In the first lesson, we’ll get your machine ready for development, install Android Studio, set up a new project, and set up an AVD (you’ll find out what that is shortly).

Let’s begin by getting Android Studio installed on your machine. If you already have it installed, make sure to update it to the latest version. Here’s the link .

The first time you run Android Studio, you’ll have to configure it.

3AbEZzb.png!web

Select Next, Choose Standard installation type, Select Next again. Select your UI Theme. As you can see above, I’m a big fan of the dark or else “Darcula” mode as opposed to the Light mode. As a developer, you’ll spend a major part of your life staring at the screen and the dark mode is much easier on the eye. Therefore, I would implore you to also opt-in for the dark mode and show your eye-sight some appreciation. Excuse the digression.

Next up is SDK components setup. Make sure to tick Android Virtual Device component and press Next one last time.

Android Studio will now download all the required components, so it may take a while, depending on your bandwidth.

Once ready, Android Studio will launch and you’ll be presented the following screen, which means we’re open for business.

E77bA3y.png!web

Start a new Android Studio project, select Empty Activity, and press Next.

Give your project a name, ensure Kotlin is selected as the language, and make sure to tick AndroidX artifacts i.e.

uMviqiE.png!web

Press finish and your Hello World app is ready! But how do we run it?

Now you have two options. You can either run the app on a physical device (assuming it runs Android 5.1 or higher) or you can set up an AVD on your machine. AVD is an Android Virtual Device, which is an emulated Android device running on your machine. It’s great because that means you can test your app on different versions of Android with different screen sizes. You can even emulate a tablet!

If you’d like to use your physical phone, you’ll need to enable Developer mode on it. You can easily find how to do it if you google it.

I’ll show you how to set up an AVD, and then, we’ll run the app, and this will conclude our first lesson.

Let’s open the AVD manager by clicking Tools > AVD Manager. Then, click on Create Virtual Device button. You’ll see the prompt to select the “hardware” you’d like

QjaUFvv.png!web

I usually choose the Nexus device as it is Play Store compatible and fits in nicely on my MacBook Pro screen. Then, finally, select the version of Android you’d like — I suggest you go with the latest and the greatest, i.e. Android Pie API Level 28. Press Next, give your device a name, and select Finish .

Now, we are ready to run our super sophisticated app!

Under the Run menu, choose ‘Run app.' You’ll be asked to Select Deployment Target. That’s your newly created AVD. For convenience, make sure to tick ‘Use same selection for future launches.’

nINneej.png!web

Now, your AVD should launch, and hopefully, you’ll see a glowing ‘Hello world’ from Android!

rMVZraM.png!web

Note: If your app crashes on the first run, it’s possibly caused by the old version of Constrain Layout — in which case you must go to your build.gradle (Module:app) file and replace

implementation 'androidx.constraintlayout:constraintlayout:1.1.2'

with

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Conclusion

In the first part of the series, we got your development machine setup and ready to get you started on a journey to Android mastery. Or at least some level of adequacy. In the next lesson, we’ll cover some basic theories, including activities, fragments, and activity life cycle.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK