Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Saturday, March 21, 2015

Say Hello to Android - Your very first Android App

For installation instruction follow my post on Android App development on a Mac. This post is written with an android studio version 1.0.1.

Open Android Studio. Create a New Project.


In the project Wizard, set up the App name to be HelloWorld. Then provide a package name. Remember that the package name should be globally unique across all packages installed on Android. Next, choose your project location and hit next.

Now you have to choose the minimum SDK version.

There is also something known as Target SDK. The Android Studio automatically sets the target SDK for you to the latest Android version. However, in order to develop an Android App, its important for you to know the difference between the two.
The Min SDK acts as your low pass filter. The Google Play wont show your app on a device running a lower version than your Min SDK. However, the target SDK does not act as a high pass filter. This only declares which platform, your app has been tested on.

Next, we have to choose an Activity. We choose a Blank Activity with Fragment. An activity serves as a presentation layer for the UI and a fragment represents a behavior or portion of the screen.

Next, we have the option to modify the names of the files auto-generated from the Wizard.

The layout will come from activity_main, which is an XML file. Similary, the fragments layout will come from fragment_main which is also an XMl file. When you click on Finish, you will see the project structure as seen in the screenshot below.

Make sure that your Android device is connected via USB and USB debugging is enabled on device. Hit run for the project in Android Studio

Congratulations!!! You have your HelloWorld App running on your device.

Sunday, March 1, 2015

Android App development on a Mac

I started with Android development yesterday, and getting to run the Android App on my phone took some struggle. I hope that this post helps the naive android developers to get started with building their first App.
OSx version : Yosemite 10.10.1

For developing an Android App, you need the following to be installed.

Install Java


First check whether Java is installed or not. On your terminal, type
$java -version
If you have Java 6.0 or above, you can skip to setting JAVA_HOME, else please download JAVA SDK from Java install page

Now set JAVA_HOME in your ~/.bash_profile to following:
export JAVA_HOME=$(/usr/libexec/java_home)
export JDK_HOME=$(/usr/libexec/java_home)

On the terminal window, type the following command:
$ source ~/.bash_profile

Install Android Studio


Get started by downloading Android Developer Studio. You can get this from the Android Developers Site.
After setting up Android Studio as per the instruction given on the site, you can get started by developing your first Android project.

Setting up USB debugging on your Android device


Plug in your device to your Mac and then enable USB debugging on your phone. This can be found in Developer Options on your android phone. Note that, the developer options is hidden by default on Android devices with version 4.2 and above.

To find the secret menu, click on settings App. Scroll down to About Phone.

Then go down to Build Number and tap on that 7 times.

Then when you go back to settings, you will see the developer options menu appear.

Enable USB debugging on device.

Getting you Mac to detect your Android device


Ideally, your Mac should detect your phone by default. However, for some reason, this may not happen. Follow the following steps to make your Mac detect your phone.

1. Make sure that adb(Android Developer Bridge) is included in your path. The default location for adb is:
~/Library/Android/sdk/platform-tools/

2. Include the following line in your .bash_profile.
export PATH=/usr/local/sbin:$PATH:~/Library/Android/sdk/platform-tools/

3. On the terminal window, type the following command:
$ source ~/.bash_profile

4. Next add the Vendor ID to ~/.android/adb_usb.ini. But first you have to find the Vendor ID value. You can do this from the System Information Application. Fortunately on Mac this is pretty easy. Launch the System Information application.
From the Hardware Menu in the left pane -> Select USB -> In the right pane, you will see the list of USB devices, select your phone from it -> In the lower pane on the right, you will see the vendor id. Copy this vendor id to the file ~/.android/adb_usb.ini

5. Restart adb
$ adb kill-server
$ adb devices

The device should be listed.

Thats it, you are all set for developing android apps and testing them on your mobile