Android is one of the most popular mobile operating systems (and it is based on the Linux kernel too.) However, diving into developing apps for Android can appear to be a bit daunting at first. The following how-to runs you through the basics of setting up an Android development environment on your Fedora machine. The basic workflow is to download the Android SDK, use the SDK to generate a quick first “hello world” application, then test out that application with either a physical Android device or the Android emulator.
Let’s get started!
Install needed Dependencies
First up we need to install a few packages from the Fedora Repos to make sure everything works correctly. To install these packages, run the command:
sudo yum install zlib-devel.i686 ncurses-devel.i686 ant
Note that the 32bit libraries in the command above are needed even if you have a 64bit install of Fedora.
Get the SDK
Now we need to create a new directory in your home directory to contain the Android SDK and your first project. I decided to name mine android-development:
Now, go to the Android SDK Download page and Download the SDK for Linux. Note that there are two types of download offered on the Android Download page, in this example we are after the SDK Tools Only option, not the ADT Bundle.
After downloading, unpack the bundle into the android-development/ directory.
Update the SDK
Now that you have the SDK you will need to update it. To do this, we need to go to the tools directory in the SDK, and then run the Android SDK Manager:
The Android SDK Manager will appear, and will prompt you to install a number of updates. It will install them directly into the android-sdk-linux/ directory.
Set up your PATH variable to point at the SDK
Next up, we need to configure your path variable to point at a couple of directories in the Android SDK so we can run them as commands in bash. So open up the
file in your favourite text editor, and add the following lines to the bottom of the file:
export PATH=$PATH:~/android-development/android-sdk-linux/tools/ export PATH=$PATH:~/android-development/android-sdk-linux/platform-tools/
Now log out of your desktop, and log back in to apply this change.
Create the App
Before we create our app, we need to know what version of the Android API we want to build against. Run the following command to see what Android API versions your SDK can target:
android list targets
I only have the most recent version of android downloaded in my SDK, so I got the following output:
Available Android targets: ---------- id: 1 or "android-19" Name: Android 4.4.2 Type: Platform API level: 19 Revision: 3 Skins: WSVGA, HVGA, WXGA800, WVGA800 (default), WQVGA432, WXGA720 Tag/ABIs : no ABIs.
In this output, all we are concerned with is the ID of the API version we want to build against. In the example above, we just need “android-19”
Now, run the following command to create a default Android project (being sure to enter in the correct directory location for the path option and the ID from above for the target):
android create project --target android-19 --name MyFirstApp --path ~/android-development/MyFirstApp --activity MainActivity --package com.example.myfirstapp
Building your Android app
Now that you have done all the prep work, building your first Android app is actually pretty easy. First change into the directory that contains your app:
then run the following command to build the app:
If the build is successful, the following command will have created a an Android application package file (apk) file at
Test out your app on a real device
Now we have a built APK of our app, it’s time to try it out on an android device. To Install the APK to a device via USB, you need to enable USB Debugging mode on your device. Note that this step is different depending on the android version your device is running.
- For Android 3.2 or older, the USB Debugging option is under Settings > Applications > Development in the android menus.
- For Android 4.0 and 4.1 the USB Debugging option is under Settings > Developer options.
- For Android 4.2 and newer, the USB Debugging option is still under Settings > Developer options, but that menu item is disabled by default. To show the Developer Options, go to Settings > About phone and tap the Build Number item 7 times.
Now you have enabled USB Debugging mode, connect your device to your Fedora machine with a USB cable, and run the following command (make sure you are still in the
adb install bin/MyFirstApp-debug.apk
Now check your phone for the newly installed app (it will be called MainActivity). Run it and bask in all the Hello World goodness:
Test out your app on the emulator
Luckily, If you don’t have a Android device handy, or if you want to try out your app on a different style of device, the Android SDK also includes an the Android Virtual Device Manager to start a whole bunch of Android device emulators. To start the Android Virtual Device Manager, run the command:
In the “Android Virtual Devices” tab, press the New… button to create a new virtual Android device. Fill out the details in the dialog and press OK:
Now, follow the same steps as if you were installing on a real device. run the following command (make sure you are still in the
adb install bin/MyFirstApp-debug.apk
Now check the emulator for the newly installed app (it will be called MainActivity).
Now you have successfully set up your build and testing envrionment for Android apps on Fedora, the best place to go to get further information about developing apps for android is the Training section at Google’s Android Developer page.