Sunday, December 29, 2013

Android Application - Develop,Build & Run Without Eclipse or any IDEs

We are generally using Eclipse IDE and ADT Plugin for developing Android applications. I too am doing the same in my mac. But few days back, something struck me, Android is an open-platform, and as such, we can create,build and test a java program without an IDE, simply using text editor,jdk and command line. On its core, programs for android are written in Java only. So why can't we try out doing the same for Android. Googled out, to surprise, its there in developer forum site itself. My bad, 2 years in android development, but in a hurry have never noticed it.

There are no hard steps to take off. Its very simple. We can create,run/debug as well get release version of apk using only command line and text editor along with Android SDK and Java JDK. No IDEs required !!

Before Getting Started
1. Download the Android SDK, Java JDK and Ant.

2. Add the android sdk, java jdk and Ant installation folder to the path variable. Please refer my blog on how to add path variables in mac.

3. Go to terminal and type the below,
        android list target
    to know the list of available android apis in the sdk. Download relevant apis using sdk manager. Note down the target id which you want to set as minsdk. To open sdk manager from command promt, type android

Creating a Project
1. Open terminal and type the below code,
   android create project --target 3 --name MyAppWithoutEclipse --path /Users/badrionapple/Documents/workshop/MyAppWithoutEclipse --activity MainActivity --package com.terminal.app
 Here --target     ->  Min SDK
          --name     ->  Project Name
          --path       ->  Physical location in the disk
          --activity  ->  Name of Main Activity
          --package ->  Package name for the app.
On successful completion, you will be able to find the full project structure being created in the location specified in path argument.

2. Edit manifest file, layouts, activity etc., as per your requirement.

Adding Libraries,Updating Projects
Please refer the link here.

Building and Running
Android projects are built using Ant tools. You will be able to find "Ant" folder in <android-sdk>/tools/.
1.Go to the root folder of your application and type the below in terminal,
    ant debug
  Compilation and build path errors will be listed, if any. On successful build, Now you have your apk signed in debug mode. You may, in addition face bufferoverflowexception, please refer here to solve it.
2. Opening emulator is easy. To know emulators i.e avds available, type android list avd in terminal. Managing AVDs from command line.
3. Type the below code, to start your avd, in terminal,
     emulator -avd <your-avd-name>
    [Note : You must have added both <android-sdk>/tools as well as <android-sdk>/platform-tools to path variable]
4. Verify whether avd is successfully started in terminal using below command,
     adb devices
5. Once your avd is listed, type the below to run your code,
     adb install bin/<your-Project-name.apk>

Distributing APKs
Please refer here.

Constraints that you may face while using command line,
  •  Unable to set breakpoint and debug your code.
  •  No Drag & Drop UI in xml for layouts, resources as well for manifest.
  •  Need to Set up everything manually for avds.
  •  Debugging is quite unfriendly(finding compile errors etc., and correcting it).
  •  No Ctrl+Shift+T or R to search classes,resources or search keywords in full workspace and other facilities that comes up with Eclipse or any IDE.


References
http://www.anddev.org/novice-tutorials-f8/developing-android-apps-without-eclipse-t13912.html
http://developer.android.com/tools/projects/projects-cmdline.html
http://developer.android.com/tools/building/building-cmdline.html
http://developer.android.com/tools/devices/managing-avds-cmdline.html



No comments:

Post a Comment