The world of mobile computing and apps is a huge area of growth. Android app development is a huge component of this market, and it isn't hard to get started. An Android developer license is all you need to load your apps on the Google Play store, and that only costs a once off payment of $25, which is a lot cheaper than the $99 per year cost of having an app on the apple app store. In this tutorial I will go over the setup required for android development and an introduction into android app development itself.
How are android apps coded?
By far the most popular language for coding android apps is Java, because the android app system is actually a variant of the Java Virtual Machine called the Dalvik Virtual Machine. Android apps come in APK files, which are analgous to Java JAR archives. It is therefore important that if you want to start android app development that you have a working knowledge of Java syntax. Android app structure is different to how desktop computer programs are coded in Java, so knowledge of many aspects of Java isn't required, but it certainly helps to be familiar with the language.
Here is a Java tutorial I wrote if you want to get started learning Java: [Tutorial] [LEGENDS] Ultimate Java Tutorial | Huge and Detailed | Beginner Friendly
Setting up for development
First up, you will need to download and install these things:
- Java Development Kit (JDK)
- Android SDK
- An IDE
There are a number of IDEs you can choose from, and it is pretty much personal preference which one you choose. The most popular are:
The first 2 are supported by Google. Personally I use Eclipse, but the Android Developer Studio comes with everything set up in advance and Google is pushing for it to replace the eclipse plugin entirely, so you may prefer to download that instead. I will cover setting up Eclipse on Windows in this tutorial.
Setting up Eclipse
First, make sure you have downloaded and installed the Java Development Kit (and that it is set up correctly in your system path). The JDK is required for any Java development.
Next, download the latest version of the Eclipse IDE for Java Developers. At the time of this writing, the latest version was Mars. This can be downloaded here: https://www.eclipse.org/downloads/packag...pers/marsr
Once you have installed Eclipse, you will need to set it up for android development. We do this by installing the Android Developer Tools (ADT) plugin in Eclipse, and downloading the Android Software Development Kit (SDK).
Head to the download page for the android SDK tools here: https://developer.android.com/sdk/index.html#Other
Download the zip archive for windows. Once it has finished downloading, extract it and run SDK Manager.exe. Once the software is loaded, go through the list and select the SDK platforms for each version of android you will use for compilation. At minimum, make sure you have:
- Android SDK Tools
- Android SDK Platform-tools
- Android SDK Build-tools (highest version)
- The latest android version SDK platform
- A system image for the emulator, such as ARM EABI v7a System Image
To install the ADT plugin, start Eclipse, open the Help menu and choose "Install New Software". It will look like this:
Spoiler (Click to View)
Click on "Add", and a box will pop up. Enter "ADT Plugin" for the name, and for the location, copy and paste this URL:
https://dl-ssl.google.com/android/eclipse/
Spoiler (Click to View)
Click OK. The "Developer Tools" should appear in the list of available software, just tick the box and click next, next again, agree to the license and then click finish. Eclipse will install the software and when it is done you will need to restart.
Spoiler (Click to View)
Once you have the ADT plugin and the Android SDK, all you need to do is link them up. Open Eclipse and head to Window > Preferences. Click on Android in the side menu, and browse for the location of your SDK. Then click Apply, and the SDK platforms you downloaded should appear in the list.
Spoiler (Click to View)
This process is very similar in Android Studio, so you should be able to work it out. Now you are ready to start coding :)
Add caption |
Making your first Android application project
In eclipse, click File > New > Android Application Project. If that is not an option, just choose "Other" and a box will pop up. Android Application Project should be in the Android folder.
Spoiler (Click to View)
You will then need to enter an Application Name, Project Name and Package Name. The Application Name is the name of the app everyone will see when they download it. Project name is just the name of the project in eclipse and only you will see it. Package name is a unique identifier for your app. It is common to use a domain you own in reverse, to ensure it is unique to you. An example package name looks like this:
com.example.androidapp
You don't have to own the domain, it just helps keep things unique. You could make one up that you like.
Minimum SDK required should be set to API 8: Android 2.2 (Froyo), unless your app can only run on later versions. "Compile with" should be set to the latest SDK platform you downloaded.
Next you will need to choose an icon for you app. You can change it later if you want to. Just select an icon and eclipse will automatically generate all the different sizes you need. It is also easiest if you let eclipse automatically create a black activity for you to start with. Once you have set everything up, click finish and you will have a new android application project :)
Android app development basics
Let's take a look at the project.
All your java source code goes in the source folder, and you can see the MainActivity.java file that eclipse automatically generated for you. This is where your app starts, when someone runs it on their device. I have pointed out the important parts of the project, most of the rest you don't need to touch. The drawable-XXXX folders hold images, there is a folder for different screen densities, and your app will automatically use the correct one based on what device it is being run on. The icon you chose at the start will be in these folders. The values folders hold string values, this is designed to allow multilanguage apps because you can create folders for different languages and android will choose the right language accordingly. The AndroidMainfest.xml file is one of the most important files in the project. It controls pretty much everything, including app permissions, what activity launches on startup, etc. On Android, all apps have permissions to allow them to access different things like storage, internet, etc. so if your app needs to access one of these, just add that as a permission in the android manifest.
Let's now have a more detailed look at 2 things: Activities and Layouts
.)
Activities and Layouts
On Android, apps do not use 'windows'. An activity is kind of like a windows for android. When you first load up the app, the AndroidManifest.xml tells android to run MainActivity. If you take a look at the code, it might seem a bit confusing at first. The thing to note is this function:
Whenever an activity is run, the onCreate() method is called, so this is pretty much the starting function (like main() in desktop Java). Activities have a lifecycle which looks like this:
Spoiler (Click to View)
Now let's look inside the onCreate() function. The default function only does one thing of note: setContentView(R.layout.activity_main); This is where layouts come in. To display things to the user, activities use layouts. Layouts are found in the layout folder on the diagram, and are written in xml. Eclipse has a nice graphical layout editor to help with designing these. The default layout, called activity_main.xml, contains only a single TextView:
So all this app does, is show the layout which has a single textview on it. The value of the text view is @string/hello_world, which is a reference to a string found in the values folder in strings.xml. If we take a look, we can see that this translates to "Hello World":
Spoiler (Click to View)
There are a lot of things at your disposal to add to a layout, including buttons, textboxes, switches, sliders, loading symbols, images, etc. When using controls such as buttons, you have to write some code to actually make it do stuff, and that code goes inside the activity not the layout.
An example, if you add a button to the layout like this:
Notice that I hardcoded the string "Click Me" in instead of using a string resource. This is a bad habit, I am just doing it for example. You should always use string resources
We have added an onClick element to the button, which has the value doSomething. This is the name of a function we will write in the activity:
Of course, most apps won't consist of just one activity. Most apps will have multiple activities, for example a menu activity with buttons, a settings activity with a settings layout screen, etc. To switch from one activity to another, we use an 'Intent'.
To demonstrate, let's start a new activity when the button is clicked. First we need to make the new activity. Right click on the project, New > Other, open the android folder and choose "Android Activity". Make a new blank activity, call it whatever you like, e.g. SecondActivity. This will also automatically create a new layout for the new activity.
Now, inside the button click function doSomething(), we can add this code:
This will open the SecondActivity when the button is clicked, and so the onCreate() method in SecondActivity is then called. Intents are used for communication between activities including the starting of the whole app, because if you look inside AndroidManifest.xml you will see that the MainActivity has a filter to accept starting intents:
You should also notice that SecondActivity has been added to AndroidManifest.xml
I don't have the time to go into much detail here, this is only the very basics of how to code an android app. After reading this tutorial, I would suggest getting a book on android development if you are still interested, because that can go into a lot more detail. Here is my personal collection of great android books to get you started: [Release] Best Ever Collection of Android Ebooks!
Running your app
There are 2 ways to test your app once it is coded. You can either run it on a physical device, or on a virtual device on the computer.
To use a physical device for testing, you must put it into developer more in the settings (google this if you don't know how to do it). Then, plug your device into your computer and it should install the drivers automatically.
To use an Android Virtual Device (AVD), click Window > Android Virtual Device Manager. The AVD Manager will open, and you can add a new AVD by clicking "Create" on the right hand side. Just give it a name, and you can choose to use the same settings as one of the real devices (e.g. Nexus 10), or you can set all the settings manually. Example:
Spoiler (Click to View)
In Eclipse, choose Run > Run Configurations to make a new run configuration for your app. On the left, choose "Android Application" and then create a new one. Give the configuration a name, and browse for the correct app project (at this point you probably only have one option xD). It should look like this:
Spoiler (Click to View)
Then, click on the Target tab, and make sure that the target is set to either your physical device or the virtual device you made. To run your app, just click Run. If you are using a physical device, make sure it is unlocked, and you should see your app open up on the screen after it installs. The virtual devices are extremely slow, but if you are using one, it will open a window, boot up android, and then open your app.
Loading your app on the Google Play Store
Once you have finished your app, you can export it to an APK file in eclipse by right clicking on the project
Spoiler (Click to View)
If this is your first app, you will then need to make a keystore, but if you have done this already then you can use your existing one. A keystore is used to sign your app to verify that it was made by you. The keystore needs a password to protect/use it. Save it somewhere safe. You will then need an 'alias' for your app in the keystore, a new alias is used for each app. A new alias requires a name, some personal details from you, a password and a validity duration (25 years is recommended). Then simply save your new APK somewhere and you have an app :)
Once you have purchased a Google developer license, you can log into your Google developer console and create a new listing for your app. You will need to upload the APK, write descriptions and add images and screenshots. After that is all done, you can publish the app to the store and it will be available to download by everyone :)
You can use the developer panel to update the app, track downloads, etc.
From here
This tutorial only covers the groundwork to get started. From here, you will need to actually get started coding, try making an app from start to finish - it will be great practise even if the idea for the app isn't great. The best way to learn development is through practise, and whenever you find something you don't know how to do / understand, look it up and learn from it. Here are some places with a wealth of information and tutorials on android development:
I wish you luck on your android development journey.
On Android, apps do not use 'windows'. An activity is kind of like a windows for android. When you first load up the app, the AndroidManifest.xml tells android to run MainActivity. If you take a look at the code, it might seem a bit confusing at first. The thing to note is this function:
Whenever an activity is run, the onCreate() method is called, so this is pretty much the starting function (like main() in desktop Java). Activities have a lifecycle which looks like this:
Spoiler (Click to View)
Now let's look inside the onCreate() function. The default function only does one thing of note: setContentView(R.layout.activity_main); This is where layouts come in. To display things to the user, activities use layouts. Layouts are found in the layout folder on the diagram, and are written in xml. Eclipse has a nice graphical layout editor to help with designing these. The default layout, called activity_main.xml, contains only a single TextView:
So all this app does, is show the layout which has a single textview on it. The value of the text view is @string/hello_world, which is a reference to a string found in the values folder in strings.xml. If we take a look, we can see that this translates to "Hello World":
Spoiler (Click to View)
There are a lot of things at your disposal to add to a layout, including buttons, textboxes, switches, sliders, loading symbols, images, etc. When using controls such as buttons, you have to write some code to actually make it do stuff, and that code goes inside the activity not the layout.
An example, if you add a button to the layout like this:
Notice that I hardcoded the string "Click Me" in instead of using a string resource. This is a bad habit, I am just doing it for example. You should always use string resources
We have added an onClick element to the button, which has the value doSomething. This is the name of a function we will write in the activity:
Of course, most apps won't consist of just one activity. Most apps will have multiple activities, for example a menu activity with buttons, a settings activity with a settings layout screen, etc. To switch from one activity to another, we use an 'Intent'.
To demonstrate, let's start a new activity when the button is clicked. First we need to make the new activity. Right click on the project, New > Other, open the android folder and choose "Android Activity". Make a new blank activity, call it whatever you like, e.g. SecondActivity. This will also automatically create a new layout for the new activity.
Now, inside the button click function doSomething(), we can add this code:
This will open the SecondActivity when the button is clicked, and so the onCreate() method in SecondActivity is then called. Intents are used for communication between activities including the starting of the whole app, because if you look inside AndroidManifest.xml you will see that the MainActivity has a filter to accept starting intents:
You should also notice that SecondActivity has been added to AndroidManifest.xml
I don't have the time to go into much detail here, this is only the very basics of how to code an android app. After reading this tutorial, I would suggest getting a book on android development if you are still interested, because that can go into a lot more detail. Here is my personal collection of great android books to get you started: [Release] Best Ever Collection of Android Ebooks!
Running your app
There are 2 ways to test your app once it is coded. You can either run it on a physical device, or on a virtual device on the computer.
To use a physical device for testing, you must put it into developer more in the settings (google this if you don't know how to do it). Then, plug your device into your computer and it should install the drivers automatically.
To use an Android Virtual Device (AVD), click Window > Android Virtual Device Manager. The AVD Manager will open, and you can add a new AVD by clicking "Create" on the right hand side. Just give it a name, and you can choose to use the same settings as one of the real devices (e.g. Nexus 10), or you can set all the settings manually. Example:
Spoiler (Click to View)
In Eclipse, choose Run > Run Configurations to make a new run configuration for your app. On the left, choose "Android Application" and then create a new one. Give the configuration a name, and browse for the correct app project (at this point you probably only have one option xD). It should look like this:
Spoiler (Click to View)
Then, click on the Target tab, and make sure that the target is set to either your physical device or the virtual device you made. To run your app, just click Run. If you are using a physical device, make sure it is unlocked, and you should see your app open up on the screen after it installs. The virtual devices are extremely slow, but if you are using one, it will open a window, boot up android, and then open your app.
Loading your app on the Google Play Store
Once you have finished your app, you can export it to an APK file in eclipse by right clicking on the project
Spoiler (Click to View)
If this is your first app, you will then need to make a keystore, but if you have done this already then you can use your existing one. A keystore is used to sign your app to verify that it was made by you. The keystore needs a password to protect/use it. Save it somewhere safe. You will then need an 'alias' for your app in the keystore, a new alias is used for each app. A new alias requires a name, some personal details from you, a password and a validity duration (25 years is recommended). Then simply save your new APK somewhere and you have an app :)
Once you have purchased a Google developer license, you can log into your Google developer console and create a new listing for your app. You will need to upload the APK, write descriptions and add images and screenshots. After that is all done, you can publish the app to the store and it will be available to download by everyone :)
You can use the developer panel to update the app, track downloads, etc.
From here
This tutorial only covers the groundwork to get started. From here, you will need to actually get started coding, try making an app from start to finish - it will be great practise even if the idea for the app isn't great. The best way to learn development is through practise, and whenever you find something you don't know how to do / understand, look it up and learn from it. Here are some places with a wealth of information and tutorials on android development:
- Google
- Stack Overflow
- Vogella Android Tutorials
- Android API Guide
- Android Developer Training
- Kilobolt Android Game Development tutorial
- Another Android Game Development tutorial, by Java Code geeks
I wish you luck on your android development journey.
Comments
Post a Comment
Comment here.....