Automation of unique version code in android apk file name

Its really been a very long time since I have written something here. Call it due to lack of time or whatever, but the end result was that it just got put on hold.

I have been working on Android lately (well for sometime now really) and some interesting technologies like RxJava to help me with some heavy-duty tasks, Retrofit libs to help me talk to the backend effectively and some Cupboard libraries helping me manage my local database. This combo has made it all the more interesting and has kept me occupied during most of my time.

But a very interesting issue that I bumped into and the solution that I thought would be optimum and the fact that it could help many more developers who are looking at some solution that I was looking for motivated me that I share it here.

I was looking at some way to make sure that I automate my version code and make it incremental and unique without having to bother to keep track of what I was doing. I also wanted to have some way to identify uniquely what release to customer was built on what code-base. Well all this made me think of many things. Most avenues led me to solve one part of the issue individually. But hey, what if we could just use the commit id and / or the commit count effectively. But I needed to find a way to integrate it in the gradle file. After quite sometime spent on searching around, this is what I came across.

Below is a sample of the build.gradle(Most initiated in the Android world would find this pretty self-explanatory, so am not going to bore you with it again).

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
def gitCommitCount = "git rev-list HEAD --count".execute().text.trim().toBigInteger()
project.ext.set("versionCode", gitCommitCount)
project.ext.set("versionNameSuffix", "(${gitCommitCount})")

defaultConfig {
applicationId ""
minSdkVersion 15
targetSdkVersion 25
versionCode project.versionCode
versionName "1.0"
versionNameSuffix project.versionNameSuffix
setProperty("archivesBaseName", "MyProject-$versionName")

signingConfigs {
config {

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
signingConfig signingConfigs.config

packagingOptions {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,".apk", "-${variant.versionName}.apk"))

The good thing about this solution is that one can customize the above for other git commands too like the git commit id as the version name suffix.

We have moved!!

We have moved

Its nice to have a whole new place to be in. Well, decided to move here all my stuff from WordPress. And with a new and easier address to find me in, I believe its easier for all, of course including me.

Usually moving can be pain and stressful, be it your physical home or a virtual one. But this one was surprisingly a breeze.

Update to the featuring of the posts

Its been a while since last posted and realized that I owe it to the readers and followers of this blog an update why there have not been new articles regarding featuring.

Since, as you might be aware, Nokia Developer has been discontinued and hence all support to discussion board has been withdrawn by Microsoft. In effect to this, there has not been any more featuring (Quite obviously!).  Regretfully, none of the links to the previously posted articles that link to the Nokia Developer site might work.

See you around sometime soon (Hopefully) with something new…

Until then…Happy coding!

HTML Agility Pack Implementation

The Featured Discussion Board Post this week is HTML Agility Pack Implementation started by Keith Kerswell.

Keith is developing an application on Windows Phone 8. He is looking for an implementation of the HTML Agility Pack that will help him extract data out of his target webpage and display the page in his application.

Keith has tried various online samples and tutorials but is unable to implement it and wants help to find suitable resource. Neil Turner not only provides him with step by step guide on how to do it, but also helps him with some common issues and fixes. Neil gives him consistent support to see him through with the full solution, with suggestions like using HttpClient rather than WebClient for his use case.

Keith is able to completely sort out his issues and successfully implement the HTML Agility Pack.

We decided to feature this thread because it highlights how the community can help you persistently to sort out all issues.  The thread also highlights the utility of the HTML Agility Pack.

See About Featured Discussion Board Posts for more information.

Keep those interesting questions coming!

Smooth Move of Image on the Page

The Featured Discussion Board Post this week is Smooth Move of Image on the Page started by Artur Tychina.

Artur is developing an app in Windows Phone 8 using He wants to move an image object slowly across the page. He is trying to manually change the margin of the image, and then implement a timer to transform it, but can’t figure out how.

Gergely Csúcs suggests that he use the RenderTransform property while setting it to TranslateTransform. Oliver Ulm agrees that he could do that, but thinks that the transformation is happening outside the layout calculations of the visual tree. Oliver adds that he could put the image control inside a Canvas control, which would give him access to the attached DependencyProperties Top and Left. He suggests an example for animation which is supported in XAML, and demonstrates the usage of TopProperty attached by Canvas control. He also clarifies that all CLR classes that are available in C# should also be available in as well, although the interfaces may sometimes differ a bit to accommodate language nuances.

Artur tries Oliver’s suggestion of putting Image control inside a Canvas control, and it works for him.

We featured this thread because it highlighted some good tricks for Image control.

See About Featured Discussion Board Posts for more information.

Keep those interesting questions coming!

Issue while expanding and collapsing in longlistselector

The Featured Discussion Board Post this week is Issue while expanding and collapsing in longlistselector started by Vineet Jain.

Vineet is developing a Windows Phone application. He has implemented a long list selector. Each item in the list has a header and a rectangle, which can be expanded to make it visible, or collapsed. His implementation works fine when only one item is expanded, but when a second item is expanded, a space is created between the two items that is equivalent in size to the list item rectangle.

While this issue remained unsolved for a long time, the thread was recently bumped by Chovik, who wanted to know if the issue had a solution. Vineet returned to the thread and suggested that Chovik could try playing around with repositioning the ExpanderView elements, using the stack panels and grids to fine-tune. In his own case what worked for him was repositioning the ExpanderView.Header tag and also adding a new ExpanderView.Expander Template. This he backs with a sample code.

We decided to feature this thread to illustrate that it might be worth bumping an old thread even if it hasn’t been resolved, because sometimes the solution has already been identified.

See About Featured Discussion Board Posts for more information.

Keep those interesting questions coming!

Showing Wait Screen while waiting for thread to complete

The Featured Discussion Board Post this week is Showing Wait Screen while waiting for thread to complete started by DiMarco.

DiMarco wants to show some kind of wait screen while his application waits for a thread to be finished so that the results of the thread are available for use. His wait screen works when he calls it without waiting for the thread completion.  However it doesn’t work when he waits for the thread to complete before calling it. He provides samples in his post showing what he has already tried, which includes join and wait notify.

Gergely Csúcs explains how the join, which is just a displayable event, is built around an event dispatcher which queues up the events and dispatches them one by one. So when the event handler does not return (because it is waiting for the join), it will not get displayed while waiting. Later when it gets displayed, it immediately gets superseded by the next screen. He adds that the same applies to the wait loop.

Gergely also refers DiMarco to another thread where similar things were discussed in detail. DiMarco confirms that he finds Gergely’s explanation acceptable and adds that the solution in the referring thread was what he needed.

We decided to feature this thread because of the exemplary way in which the query was posted and answered, and also to show how solutions can be found in the vast bank of already answered threads on the Nokia Developer Discussion Boards.

See About Featured Discussion Board Posts for more information.

Keep those interesting questions coming!

Record a video of the filtered camera source

The Featured Discussion Board Post this week is Record a video of the filtered camera source started by Reactor15.

Reactor15 wants to know how to record a video of a filtered camera source. Lee McPherson provides him with a code sample in which one can adjust the recording settings for the particular device.

Reactor15 adds that he wants to use the ChromaKeyFilter, but it seemed to have no effect on the video when enabled. He thinks the alpha channel is being ignored. Lee does not think that those video formats (NV12 and YU2) have alpha channels, and clarifies that they use a luminance byte and two or more color bytes to construct an image. He adds that they are neither RGB nor RGBA.

Lee suggests using Blend Filter in combination with ChromaKeyFilter by running the ChromaKeyFilter on the input video, then blending that layer on top of a custom background that can be provided as another IImageConsumer. Reactor15 was able to get it working with a test ColorImageSource for the background, but wants to know how to pass a StorageFileImageSource from C# to C++. Yan Verdavaine clarifies that StorageFileImageSource implements IImageProvider, and hence he could pass it like a property. Reactor15 confirms this to be an acceptable solution.

We featured this discussion to highlight how helpful members of the community sort out issues to their final conclusions.

See About Featured Discussion Board Posts for more information.

Keep those interesting questions coming!

Windows Phone 8.1 Windows.Media.Capture API and Preview Frames

The Featured Discussion Board Post this week is Windows Phone 8.1 Windows.Media.Capture API and Preview Frames started by Oliver Ulm

Oliver finds it quite easy to access preview frames from the camera using the APIs from Windows Phone 8.0. On Windows Phone 8.1, he observes that it cannot be done the same way as in the previous version. He wants to know if there is any way to do this other than the only reference that he has been able to find.

Lee McPherson shares his experience of how he has gone about this by modifying one of the Media Foundation Transforms that exists in the Media Extensions sample for Universal Apps. He reiterates that he wants to share it on the Wiki. Yan Verdavaine refers to the Real Time Filter Demo code sample, which Lee finds to be a good solution.

We featured this discussion because it highlights ways to preview frames in Windows Phone 8.1.

See About Featured Discussion Board Posts for more information.

Keep those interesting questions coming!

Image view undesirably cropped

The Featured Discussion Board Post this week is Image view undesirably cropped started by m.findlay93

m.findlay93 is trying to implement an Image View within a page for a Windows Phone application, but when it is deployed, the image gets cropped. He states his problem and provides a screen grab of the issue faced.

Ratish Philip admits to facing the same problem. When he removes CacheMode=”BitmapCache”, the cropping goes away but the zoom and pan performance is affected. He suspects a size limit to the image and recommends taking a look at the PhotoPage.xaml in the FilterExplorer project on the Nokia Developer Github repository.

Lee McPherson confirms that the size limit does exist. In WP7 it is 2048x2048 and 4096x4096 in WP8. He suggests loading the image using DecodePixenHeight or DecodePixelWidth to reduce the resolution. The drawback of this approach is that one would lose some resolution on zooming. The alternate and cleaner solution would be to use the Nokia Imaging SDK and follow articles in the Wiki that explain how to display high resolution images.

This discussion was selected for featuring because it highlights how it is possible to work around API limitations by using Nokia Imaging SDK for high resolution pictures.

Keep those interesting questions coming!