Table of Contents#
- Prerequisites
- Installing Java Development Kit (JDK)
- Downloading Android Studio
- Installing Android Studio
- Setting up Kotlin
- Creating Your First Android Project
- Running Your Android Project
- Troubleshooting Common Issues
- Conclusion
- References
Prerequisites#
Before we begin, make sure your Ubuntu 24.04 system meets the following requirements:
- At least 8GB of RAM (16GB recommended for better performance)
- A decent amount of free disk space (around 10GB or more)
- A stable internet connection
Installing Java Development Kit (JDK)#
Android Studio requires the Java Development Kit (JDK) to be installed on your system. Follow these steps to install the JDK:
- Open the terminal by pressing
Ctrl + Alt + T. - Update the package lists:
sudo apt update- Install the OpenJDK 11 (which is compatible with Android Studio):
sudo apt install openjdk-11-jdk- Verify the installation by checking the Java version:
java -versionYou should see output similar to:
openjdk version "11.0.19" 2023-04-18
OpenJDK Runtime Environment (build 11.0.19+7-Ubuntu-0ubuntu124.04)
OpenJDK 64-Bit Server VM (build 11.0.19+7-Ubuntu-0ubuntu124.04, mixed mode, sharing)
Downloading Android Studio#
- Go to the official Android Studio website: https://developer.android.com/studio
- Scroll down and click on the "Download Android Studio" button.
- Select the Linux (64-bit) option. The download will start as a
.binfile.
Installing Android Studio#
- Open the terminal and navigate to the directory where the downloaded Android Studio
.binfile is located (usually theDownloadsdirectory).
cd Downloads- Make the
.binfile executable:
chmod +x android-studio-ide-*.bin(Replace * with the actual version number in the file name)
3. Run the installer:
./android-studio-ide-*.bin- Follow the on-screen instructions in the Android Studio Setup Wizard. You'll be able to choose the installation location, select components (it's recommended to keep the default selections for now), and configure other settings.
Setting up Kotlin#
Android Studio comes with Kotlin support out of the box. But to confirm and enable it (if for some reason it's not already set up):
- Open Android Studio.
- Go to
File->Settings(on Linux, it might beAndroid Studio->Preferences). - In the left sidebar, expand
Languages & Frameworksand selectKotlin. - If Kotlin is not installed, you'll see an option to install it. Click on the relevant button (usually something like "Install" or "Enable") and follow the prompts.
Creating Your First Android Project#
- In Android Studio, click on
Start a new Android Studio project. - In the
Create New Projectwindow:- Select an activity template (for example, "Empty Activity" is a good starting point for a simple app).
- Give your project a name (e.g., "MyFirstApp").
- Set the package name (usually follows a reverse domain name style like
com.example.myfirstapp). - Choose the location where you want to save the project.
- Select the minimum SDK version (you can start with a relatively recent one like Android 6.0 (Marshmallow) or higher).
- Make sure the language is set to Kotlin.
- Click
Finish. Android Studio will now create the basic structure of your Android project with Kotlin code.
Running Your Android Project#
- Connect an Android device to your computer via USB (make sure USB debugging is enabled on the device. You can usually find this option in
Settings->System->Developer options).- If you don't have a physical device, you can create an Android Virtual Device (AVD):
- Go to
Tools->Device Manager. - Click on
Create device. - Select a device configuration (e.g., a Pixel phone) and an Android image (like the latest Android version available).
- Follow the steps to create the AVD.
- Go to
- If you don't have a physical device, you can create an Android Virtual Device (AVD):
- In Android Studio, click on the green "Run" button (the triangle icon) or use the shortcut
Shift + F10. - Select the device (either the physical one or the AVD) that you want to run the app on.
- Android Studio will build the app and install it on the selected device. You should see your app launch on the device.
Troubleshooting Common Issues#
- Java Version Mismatch: If you get an error related to the Java version, make sure you have installed the correct JDK (OpenJDK 11 as mentioned earlier) and that Android Studio is configured to use it. You can check the JDK path in
File->Project Structure->SDK Location(underProject Settings). - Slow Performance: If Android Studio is running slowly, you can try increasing the amount of memory allocated to it. Go to
Help->Edit Custom VM Optionsand adjust the-Xmxvalue (e.g., from2048mto4096mif you have enough RAM). - Build Errors: If there are build errors in your Kotlin code, carefully check the error messages in the
Buildwindow. Common issues include syntax errors (like missing semicolons in Kotlin, although Kotlin is more lenient than Java in some cases), incorrect imports, or problems with resource files.
Conclusion#
Congratulations! You've successfully set up Android Studio and Kotlin on Ubuntu 24.04, created your first Android project, and even run it on a device. Android development with Kotlin offers a modern and productive way to build apps. Keep exploring the Android Studio features, learning more about Kotlin syntax and Android APIs, and you'll be creating more complex and useful apps in no time.