How to Build an Android application with Eclipse and Phonegap (Generate an APK file)

generate apk file

Create an .apk file after you’re done developing should be something really simple to do. After you spent so much time developing and testing your application, you don’t want to waste time about finding out how to generate an android application ready to be distributed on the Google Play store. This article will give you the steps to follow to have your Android application ready to be used on plenty of devices (assuming you are using Phonegap).

Multiple options are available

Here are the different options available for you:

  • Deploy your Android app from Eclipse on your emulator or your phone like if you wanted to debug it. Go to your /bin directory and get the .apk file inside it. (this apk will be unsigned and mostly be usable just on your phone)
  • Generate an Unsigned Application package using the Android tools and Eclipse (will be usable on some phone accepting to install unsigned applications)
  • And my favorite: Generate a signed application ready to be deployed on the market and downloaded by your friends and customers.

Some Phonegap Improvements before to build the Android “production” application

The first thing you want to do is to check your AndroidManifest.xml and make sure to remove the following line so that your application will not be run into debug mode:


The second thing you want to do is to check your index.html file (or the main page loaded by Phonegap) and make sure you are not calling any script on other port that the 80. This is likely the first cause of the following error even if everything works fine on your emulator:

The connection to the server was unsuccessful. (file:///android_asset/www/index.html)

The last thing you might want to do is to set a timeout to your app if it doesn’t load for any reason, because you don’t want your users to end up with just a black screen. Just head to you main java file (src folder) and add this line to your onCreate() function:

super.setIntegerProperty(“loadUrlTimeoutValue”, 15000);

The property “15000″ means that you give 15secs to your app to load/download all the scripts before to start. If it can’t make it then it will crash…The next steps will be describing how to generate your Android app signed with a certificate so that you can install it everywhere and make it available for download.

How to Export the Android application for Google Play (as a signed application)

  • Open Eclipse, Right click on the root of your project and select “Export”
  • Select “Export Android Application:
android app

Select Export as an Android Application

  • Create a new Keystore to store your certificate that will be used to sign your Android Application.

The Password must be 6 characters minimum.

  • Fill out the fields to generate the certificate. Organizational Unit could be your department; Organization could be the name of your company. This information is not fundamental anyway, that’s your call. The certificate validity should be 25 years minimum (yes…you read it correctly, and no there’s no typo J)


    build apk

    Fill out all the fields to sign and build your apk file

  • Then Click on Next, Select the destination where your apk file will be generated and you’ll finally be able to freely install everywhere you want!

That’s it for this article! I hope you enjoyed the tips. I know a lot of people are willing to use Adobe Phonegap Build but since I usually change my java classes, I needed a different solution…hope this will be yours too!

In case you want to generate your apk and don’t bother signing it, here is what you should do:

Right-click on the root of your project, then Android Tools, and finally click on “Export Unsigned Application package…” and follow the steps until you reach your goal.


This post was written by Bruno Didier