Showing posts with label google. Show all posts
Showing posts with label google. Show all posts

Tuesday, 26 May 2015

Android Environment Setup and basic code

Android Studio is a slightly heavy app, even in a machine with reasonable specs it sometimes hangs, yet that would do the job, just don’t run too many applications while you are working with studio. Moving on, I will first talk about the system requirements which would be any modern system with at least 2.5+GHz processor , a 4 Gb or above RAM(this is the minimum, please don’t  go below this it will kill your system).
However, for Linux users, it is recommended to install Studio in 64 bit systems. But to install Studio which is a 32 bit application in a 64 bit machine you need to have the 32-bit support library package ia32-libs.
For Ubuntu users, you can execute the below command:
sudo apt-get install ia32-libs
1)      Install Java Development Kit(JDK)
Download  and install the required JDK package from the below link which is apt for your system OS.
For windows , the JAVA_HOME environment variable. The steps of which are:
  1. Open My Computer.
  2. Go to System Properties.
  3. Open Advance system settings.
  4. Goto Advanced Tab and Open Environmental Variables.
  5. Then Click on New and Set Variable Name : Path and Set Variable Value : C:\Program Files (x86)\Java\jdk1.7.0_25\bin (The Directory In which JDK is installed.)
  6. Click OK
Verify the JDK installation by typing
java -version
from the command prompt, it should output
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)
If it works properly, else it will show command not found error
Install Android Studio
Install Android  Studio from the below link
Go through the license agreement and download the file as exe or zip. Install the exe file or unzip the zip file.
Run Android Studio, for the very first run you will get a dialog prompting  to import settings from an existing installation, followed by the setup guide.  Go through the guide and in the end press the finish button.
On starting Studio, you will be greeted with a welcome screen as follows

If you have already created projects it will be listed in the Recent Projects tab.
Now starting fresh,  click on the Start a new Android Studio project  and go through the guide. 

You can give your project a name say “HelloWorld” in camel case in the Application name field, also give a proper package name say ”com.example.firstproject.helloworld” in lower case, click next.

Select your desired platform, say you are developing a mobile app, select phone and tablet and also choose the minimum sdk version as to which version of android release can support your app(its advised to choose the lowest version, so that you app may run in most devices), click next.



Select a template, say Blank Activity. An activity is a code to support the UI. It will help you to design your application to behave as you wish in each lifecycle of the application like when the app is in foreground or background etc. The next page allows you to name your project components such as your activity, layout (a layout is view design on how you want to see each activity in your device), click Finish.

The android studio opens up with a layout displayed in front of you. You can see it contains a view with a label “Hello World”. In android all activity layouts by default comes up this way, so for now just click the play button on top if you have a device plugged in.
To run in emulator
·         Select Tools>Android>AVD Manager or click the icon https://developer.android.com/images/tools/avd-manager-studio.png in the toolbar.
·         Click Create Virtual Device
·         Select a device configuration say Nexus 6 and click next.
·         Select the version of the AVD
·         Click Finish
Once the emulator is launched and the home screen appears (it may take a while, have patience) click the run button from the toolbar and you can see the Hello World in your screen.






Android Studio and Gradle in brief

The features of the Android Studio consist of the following:
  1. Intellij or the intelligent code editor -  provides powerful code editing, code completion, refactoring etc. so that developers can save a lot of time. This feature was available with the ADT bundle as well which was used for android development earlier.
  2.  UI - The new Studio is shaped for better developer interactions. Easily accessible tools and settings and all other development related buttons are their within reach and there is no need to fish around much. Also the Layout Editors are better designed and layout previews are more real looking.
  3.  Rich AVD - The AVD manager has a rich set of devices in all shapes and sizes. This is one great boon.
  4.  Built in google cloud support.
  5.  Build tools - This is one of the most confusing point for developers who switched from eclipse. I would be going to this in detail hence.
    • Android Studio makes use of the Gradle build tools which is an automated build toolkit, basically a plugin. It consists of a set of files to configure and manage the build process. The scripts are based on the Groovy programming language.  
    • Compared to Eclipse IDE, where the developers were unaware about the backend apk building process, Android studio’s Gradle allows a seamless way for developers to manage their builds. With this plugin you will be able to build different versions of the same project like paid, unpaid or device specific apks etc. Developers can also trigger the build from command line as well.
    • The gradle allows including dependencies from within your local repos as well as remote repos. The gradle build normally takes place by assuming a default project convention or structure. It also gives you the freedom to alter your project structure; only, you have to make sure to configure the build files accordingly.

There are two levels of build files: module build file and project build file.  The project level build file is the topmost and it will contain basic information. An example project gradle file is as follows:
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
         // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
 allprojects {
    repositories {
        jcenter()
    }
}

This file simply states that the build is based on the Android plugin and all the remote libraries will be obtained through the jcenter repository.
The Module build file contains the module wise build configurations. It also allows                 you override the main manifest file setting and configure custom packaging/compiling              option etc.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.demo.sample"
        minSdkVersion 19
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
debug {
            debuggable true
        }

    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:+'
}

Thursday, 21 May 2015

Environment Setup


Today, there is a huge mass of android developers out there. Earlier the android developers only used the Eclipse IDE for their development purposes, but, these days Google is encouraging developers to get use the Android Studio. Though Googles words are strong most developers still use the Eclipse out of habit. Jokes apart, lets start...

For android development you need to :

  1. Download the Android Studio.
  2. Download the latest SDK tools and platforms using the SDK Manager.



Android - from scratch



Android is an OS not a Language


                   Lets start with this phrase, this simple fact that Android is an OS based on the Linux kernel and not a language. The Project was lead by Google and was called as the Android Operating System Development(AOSD). Today billions of Android users are there around the world. Many huge mobile development companies such as Samsung, Sony etc have built and released billions of Android devices. Being one of the most widely used platforms of the current times, along with the user account Android also has a long line of development communities.