how to generate apk file using a command line?

You’ll have to have Apache ant for this one:

ant debug

This will build and sign the necessary .apk files.

For more info, please see this: http://codeseekah.com/2012/02/09/command-line-android-development-basics/

EDIT:

ant is not a part of standard Android SDK setup. You'll have to install it.

Download the latest ant zip file from The Apache Ant Project.

Extract the zip file to a folder, say c:\ant\ 

Add c:\ant to your path environment variable

Once these are done, you'll be able to run ant from the command line


The apk by default is located under bin and this is correct, but when you distribute source code it's better to not add any apk because a "fresh" compiled apk is always a better solution.

if you have a file called build.xml in the root of your project just do

ant debug

otherwise you need to update your project with the minimum informations required for the building phase with

android update project -t android-10 -p .

in this case android-10 is a target for your apk/app/api and you can customize this option for your targeted device.

After this you get your build.xml and everything is in place for generating an apk.