Friday, August 1, 2014

Releasing a Signed Cordova Apk from NetBeans 8

I'll show how to build a cordova android app in NetBeans 8, and release a signed apk file.

The first part is relatively easy. Start up NetBeans 8, and from the main menu select File -> New Project. This brings up the New Project dialog.

In the dialog 'Categories' open the Samples folder and select the HTML5 subfolder. In the dialog 'Projects', select the Cordova Maps Sample, and click Next, name the project and click Finish:

This generates the application. Open index.html in your root, connect your android phone to the usb and hit F6 to run the project.

You should see something like this on your phone:

That was the easy part. Net beans doesn't have any menu selections to build a signed apk that you can distribute. However, Cordova uses an ant build process, and NetBeans is ant friendly.

So, the first thing you need to do is create your key:

$ keytool -genkey -v -keystore myapp.keystore -alias myapp -keyalg RSA -keysize 2048 -validity 10000

The keystore utility will walk you through some questions. You'll need to enter your app name and password, app alias, alias password and developer name. The remaining can be defaulted.

Now, in NetBeans project explorer, select the files tab, and create a file named ./platforms/android/ entering the following contents:

Now you can right-click on ./platforms/android/build.xml and select Run Target -> release:

It will take a minute or two, and the ant build process will generate  ./platforms/android/bin/MyApp-release.apk, a signed distribution file.

Maybe I was wrong - with a little tlc, NetBeans does have a menu selection to build your apk!


  1. Great tutorial so far, but I do not have a target "release" in my build.xml. Any hint on this?

  2. The build.xml imports commands like release from "${sdk.dir}/tools/ant/build.xml". So you won't see that target in the file if you visually inspect it. But when you right click on it in the project explorer, the command should be selectable - netbeans stitches it all together behind the scenes.

    If you aren't seeing a release command when you right click, my guess is that netbeans isn't finding your android sdk - you can set the path to it at tools>options>Miscellaneous/Mobile Platforms.

  3. Netbeans is already running with android sdk (I am already running my project with the android device). But really no target "release" for the build.xml, see screenshot:

    1. I see the problem. You need to use the build.xml in the ./platforms/android folder - you're selecting the build in the ./nbproject folder - that one wraps the cordova command line, which, it seems. does everything except create a signed .apk :)
      I've updated the image on this posting to clarify that better.

    2. Thanks for your help, but the build.xml in the android folder has got -no- targets in its popup menu. I can only choose "advanced". I guess I will give it up.
      So far I use the signed package, delete the meta-inf folder in it ( and sign it manually over command line :(

  4. The way bruce described works with the constallation Netbeans 8.0.0 and Cordova 3.4.0-0.1.2 (thank you Bruce!). Because of a security issue on cordova I needed to update cordova. Now with Netbeans 8.0.1 and Cordova 3.6.3-0.2.13 the commands aren't found by the build.xml file. After comparing both projects I found the following difference:

    The file platforms/android/ in my new project was empty and should be generated/modified automatically.
    # This file is automatically generated by Android Tools.
    # Do not modify this file -- YOUR CHANGES WILL BE ERASED!

    I modified the file manually with the path to the sdk (thank you again bruce for the hint from 2014-10-01), e.g. for windows:


    Now the commands are found by the build.xml file. :)

  5. i dont understand this line., where should I do this code?

    $ keytool -genkey -v -keystore myapp.keystore -alias myapp -keyalg RSA -keysize 2048 -validity 10000

  6. Keytool is a command line utility that ships with the jdk. I just opened a command window in my project folder, and ran it there - in my example, that would be /home/bruce/Git/myapp/

    For a full explanation of keytool and its parameters, you can check out the oracle documentation:

  7. I don't have a build.xml file, but there is a build.gradle file. Did the build process switch from Ant to Gradle, and is this something to do with Netbeans or with Cordova? (Using Netbeans 8.0.2).

  8. I'm also using netbeans 8.0.2. My two existing cordova projects work just fine. But when I just tried to create a new one, the new project wizard fails, says I don't have cordova. What I do have is the newer version of cordova (5.0.0) - The projects that are working for me use Cordova 3.x,. It sounds like Netbeans hasn't kept up.

    I found this on cordova's doc: "Cordova for Android now supports building with Gradle. This is optional in Cordova 3.x, but will be enabled by default in the future, probably with Cordova 4.0."

    If you are married to Netbeans, I'd try downgrading the cordova version. I've actually been using AndroidStudio lately for creating APK's. Intel's XDK works pretty well, too, if you can get past the editor.

  9. This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post. Latest APK File

  10. Many Android users are not very much aware about these applications. It is quite simple and easy to learn more information about these files.

  11. This comment has been removed by the author.

  12. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.
    I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
    If anyone wants to become a Java developer learn from Java EE Online Training from India.
    or learn thru Java EE Online Training from India .
    Nowadays Java has tons of job opportunities on various vertical industry.

  13. Usually, your Android device will automatically install the APK. However, if the application that you have is not from the Android Market, you need to make sure that you install it manually in your device. This step is needed so that your apps will run successfully without any hitch.ShowBox APK

  14. Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need!Relay appreciate your work.
    Gb Instagram

  15. It is possible for a person to install APK files directly in devices. This can be done without necessarily downloading them from any network. You can use a desktop computer and use different communication programs.

  16. Excellent and very exciting site. Love to watch. Keep Rocking.
    Diving in Cabo
    Scuba Diving in Cabo

  17. Excellent and very exciting site. Love to watch. Keep Rocking.
    sfs framing
    curtain wall insulation

  18. I am definitely enjoying your website. You definitely have some great insight and great stories.
    metsec wall
    metsec cladding rails
    curtain wall detail
    timber cladding details

  19. Thanks For sharing this Superb article. I use this Article to show my assignment in college. it is useful For me Great Work.
    certified Ethical Hacker nj
    comptia linux plus nj
    mcsa certification
    mcsa certifications