In the previous article, we installed and prepared Android Studio, the main development environment for Android application development.
Now it is time to take the next step.
In this tutorial, we will create our first Android project, understand the important options shown during project creation, explore the automatically generated project structure, and run the application for the first time.
You don't need to build anything complicated yet.
Our goal is simple:
Create an Android application and successfully run it.
Once you accomplish this, you will have officially created your first Android app.
What We Are Going to Build
For this first project, we will create a very simple application.
The application will display a basic message on the screen.
Our development process will look like this:
Open Android Studio
↓
Create New Project
↓
Configure Project
↓
Android Studio Generates Files
↓
Build Project
↓
Run Application
↓
First Android AppThis may seem simple, but understanding this workflow is extremely important because almost every Android project begins with these basic steps.
Step 1: Open Android Studio
Launch Android Studio on your computer.
After Android Studio starts, you should see the welcome screen.
Depending on your Android Studio version, the interface may look slightly different, but you should find an option similar to:
New Project
Click on New Project.
This will open the project template selection screen.
Step 2: Select a Project Template
Android Studio provides different templates to help developers create applications quickly.
For our first application, select a basic phone and tablet application template.
In modern Android Studio versions, a template such as Empty Activity is commonly used for a simple Jetpack Compose application.
The exact template names and available options may change as Android Studio evolves.
For this series, we will primarily use modern Android development with Kotlin and Jetpack Compose.
After selecting the appropriate template, click:
Next
Step 3: Enter the Application Name
You will now see several project configuration options.
The first important field is usually the application name.
For this tutorial, enter:
MyFirstAppYou can choose a different name if you prefer.
The application name is the name associated with your project and can also become the name users see for the application.
For example:
MyFirstAppcould appear on the device as:
My First Appdepending on the application's configured label.
Step 4: Understand the Package Name
You will also encounter an option called the Package name or application package identifier.
For example:
com.example.myfirstappA package name uniquely identifies an Android application within the Android ecosystem.
A common structure is:
com.companyname.appnameFor example:
com.mycompany.calculatoror:
com.example.myfirstappFor learning purposes, the default package name generated by Android Studio is fine.
When you eventually publish a real application, you should choose an appropriate unique application identifier.
Step 5: Choose the Project Location
Android Studio will ask where you want to save the project.
Choose a location that is easy to find and has sufficient storage.
For example:
Documents
└── AndroidProjects
└── MyFirstAppAvoid placing projects in locations where you may accidentally delete or move important files.
Keeping all Android projects inside a dedicated folder can make project management easier.
Step 6: Select Kotlin
Modern Android development in this series will use Kotlin.
If Android Studio displays a programming language option, select:
KotlinKotlin is Google's preferred language for modern Android development.
If you already know Java, you will notice that many programming concepts are similar.
If Kotlin is new to you, don't worry.
We will learn the important Kotlin concepts throughout the series.
Step 7: Select the Minimum Android Version
Another important option you may encounter is the Minimum SDK.
The Minimum SDK determines the oldest Android version your application is designed to support.
For example:
Minimum SDK
↓
Oldest Android version supportedChoosing a lower minimum version can allow your application to run on more older devices.
However, supporting older Android versions can sometimes introduce additional limitations.
For learning purposes, you can generally use the recommended option provided by Android Studio unless the tutorial specifies otherwise.
Step 8: Create the Project
Once you have configured the project, click:
Finish
Android Studio will now create your project.
You may see messages such as:
Loading...
Indexing...
Gradle Sync...
Building...Don't be concerned if this takes some time during the first project setup.
Android Studio may need to download dependencies and prepare the project.
What Happens When You Create a Project?
This is an important question.
When you click Finish, Android Studio doesn't simply create one Kotlin file.
It generates an entire Android project.
A simplified structure looks something like this:
MyFirstApp
│
├── app
│ ├── manifests
│ ├── kotlin
│ └── res
│
├── Gradle Scripts
└── Other Project FilesThe exact structure and file names can vary between Android Studio versions and project templates.
We will explore the most important parts one by one.
Understanding the app Module
One of the most important parts of your project is the:
appmodule.
This contains the main source code and resources for your Android application.
Think of it as the main application module.
Inside it, you will find several important areas.
The AndroidManifest File
One important file is:
AndroidManifest.xmlThe Android Manifest provides essential information about your application to the Android operating system.
It can contain information related to:
Application configuration
Application components
Permissions
Services
Activities
Other application metadata
For example, an application that requires internet access may need an appropriate permission depending on how it is designed.
The Manifest is an important part of Android development, and we will study it in more detail later.
The Kotlin Source Code
Your application's Kotlin source code is stored inside the project's source directories.
For a modern Compose-based application, you may find a Kotlin file such as:
MainActivity.ktThis is one of the first files you will work with.
It contains Kotlin code that helps start the application's main screen.
What Is MainActivity?
You may have heard the word Activity before.
An Activity represents a user-facing screen or entry point into an Android application.
For example, an application might contain screens such as:
LoginActivity
HomeActivity
ProfileActivity
SettingsActivityModern Android applications can use different navigation architectures and components, so thinking of every screen as a separate Activity is not always accurate.
For now, simply remember that an Activity is an important Android component associated with a user-facing part of an application.
Your First Kotlin Android Code
A newly created Compose project may contain code conceptually similar to:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
// User interface
}
}
}Don't worry if you don't understand every line yet.
Let's break down the important parts.
class MainActivity
class MainActivity : ComponentActivity()This creates a class named:
MainActivityIt extends ComponentActivity, which provides functionality required for this type of Android application.
We will learn about classes and inheritance in detail when we study Kotlin.
onCreate()
You may see:
override fun onCreate(...)The onCreate() method is called when the Activity is being created.
It is one of the most important lifecycle methods of an Activity.
We will later study the Android Activity lifecycle in detail.
setContent
In a Jetpack Compose application, you will commonly see:
setContent {
...
}This is where the Compose user interface is defined.
For example:
setContent {
Text("Hello Android!")
}This tells Compose to display a text element.
Step 9: Build Your First Application
Before running the application, Android Studio needs to build it.
Building an Android project involves processes such as:
Source Code
↓
Compile
↓
Resolve Dependencies
↓
Package
↓
ApplicationYou can use the build options provided by Android Studio to check whether your project compiles successfully.
If there are no errors, you're ready to run it.
Step 10: Choose a Device
To run your application, you need an Android device.
You generally have two options:
Option 1 — Android Emulator
Use a virtual Android device running on your computer.
Option 2 — Physical Android Phone
Connect an Android phone configured for development.
If you already created an emulator in the previous setup article, select it from the device selector in Android Studio.
For example, you may see something similar to:
Pixel DeviceThe exact device names depend on the virtual device you created.
Step 11: Run the Application
Once your device is selected, click the Run button in Android Studio.
Android Studio will:
Build the application.
Install it on the selected device.
Start the application.
Display the application interface.
If everything works correctly, you should see your first Android application running.
Congratulations!
You have created your first Android application.
What Happens Behind the Scenes?
When you click Run, several things happen.
A simplified process looks like this:
You click Run
↓
Android Studio starts build
↓
Gradle processes the project
↓
Kotlin code is compiled
↓
Application is packaged
↓
App is installed
↓
Android launches the appYou don't need to manually perform each of these operations.
Android Studio and the Android build system handle them for you.
Change the Text on the Screen
Now let's make a small modification.
Find the part of your Compose code responsible for displaying the default greeting.
You may see code resembling:
Text(
text = "Hello Android!"
)Change it to:
Text(
text = "Welcome to My Android App!"
)Run the application again.
You should now see:
Welcome to My Android App!This is your first small modification to an Android user interface.
A Simple Example
Your application can contain a composable function like:
@Composable
fun Greeting() {
Text(
text = "Welcome to Android Development!"
)
}The @Composable annotation indicates that the function can be used to describe UI in Jetpack Compose.
Later, you will learn how to create much more sophisticated interfaces using composable functions.
What Is a Composable Function?
Jetpack Compose introduces an important concept called a Composable function.
A composable function is a Kotlin function that describes part of your application's user interface.
For example:
@Composable
fun WelcomeMessage() {
Text("Hello Android!")
}You can think of it as a reusable UI building block.
For example:
Application
│
├── Top Bar
├── Welcome Message
├── Image
├── Button
└── FooterEach section can potentially be represented using composable functions.
This makes it easier to organize larger interfaces.
Understanding Resources
Android applications can contain resources such as:
Images
Icons
Strings
Colors
Fonts
Other configuration resources
Traditionally, these are often organized under the res directory.
Even though Jetpack Compose allows much of the UI to be written directly in Kotlin, Android resource management remains an important concept.
We will learn how to work with resources later.
What If the App Doesn't Run?
Don't worry.
Errors are normal in software development.
If your application doesn't run, check the error message.
Common problems include:
Gradle Sync Error
Your project may not have successfully synchronized its dependencies.
SDK Problem
A required Android SDK component may be missing.
Emulator Problem
The virtual device may not have started correctly.
Compilation Error
There may be an error in the Kotlin code.
Insufficient Resources
Your computer may not have enough available RAM or storage.
The important rule is:
Don't randomly change settings when you encounter an error. First understand what the error is telling you.
Your First Android Development Workflow
You have now experienced the basic workflow that you will use repeatedly.
Create Project
↓
Write Code
↓
Build
↓
Run
↓
Test
↓
Find Errors
↓
Fix Errors
↓
Run AgainThis cycle is at the heart of software development.
As your applications become larger, the process will become more sophisticated, but the basic idea remains the same.
Practice Exercise
Before moving to the next article, try making a few changes to your application.
Exercise 1
Change:
Hello Android!to:
My First Android ApplicationExercise 2
Change the message again to:
I am learning Android development.Exercise 3
Try creating another composable function.
For example:
@Composable
fun DeveloperName() {
Text("Android Developer")
}Then experiment with displaying it in your application.
Don't worry if you make mistakes.
Experimenting is one of the best ways to learn programming.
What You Learned Today
In this article, you learned how to:
Open Android Studio
Create a new Android project
Select a project template
Choose Kotlin
Understand the application name
Understand the package name
Choose a project location
Understand the Minimum SDK
Understand the basic project structure
Locate Kotlin source code
Understand
MainActivityUnderstand
onCreate()Understand
setContentCreate a simple Compose UI
Build an Android application
Run an application on a device
Most importantly, you created and ran your first Android application.
What's Coming Next?
We have successfully created our first application, but we still have a lot to learn.
In the next article, we will step back for a moment and learn an essential foundation:
Kotlin programming fundamentals.
Before creating complex Android applications, you need to understand the programming language used to build them.
We will start with:
Variables
Data types
valandvarStrings
Numbers
Boolean values
Basic operators
Simple Kotlin programs
Once these fundamentals are clear, we will gradually return to Android development and use Kotlin to create real application features.
Final Words
Creating your first Android application is a small achievement, but it is an important milestone.
You have now gone from:
"I want to learn Android development"to:
"I have created and run an Android application."From this point onward, the focus will shift from simply running an application to understanding how to build one.
Keep experimenting with your project, change the text, break things, fix them, and become comfortable inside Android Studio.
The more you practice, the more natural Android development will become.
Comments
Post a Comment