Disallow debug logging in Android release build

Android_Robot_200So I’ve been doing a lot of Android development over the past several months, and came across the question of how to provide debug logging for a debug build of the library/app I’m working on, but to not let those debug logs flow through to the release build.

At first I mistakenly assumed that, hey, it’s a release build, so surely Log.d and Log.v calls won’t show up?  Wrong.  Android release builds don’t care about debug level, they’ll show whatever logging, at whatever logging level you tell it to.

So at first I sat and thought how I could fix the problem.  I came up with a few options:

  1. I could do what the Android Developer guide suggests one does, and comment out all my debug log lines before building a release build.  Ya, right, uh, no.
  2. I could wrap all the debug log lines with if(BuildConfig.DEBUG) { … }, but that felt unnecessarily painful to have to do.
  3. I could create my own Log class, with its own logic on when to actually log (such as a point 2 above, at the very least), and then just call the android.util.Log methods, but that kind of felt like overkill, as surely the expectation to have intelligent logging on Android is not that wrap the existing logging with your own…
  4. I could switch to old familiar Log4J (or Android equivalent); but yuck, that’s _really_ overkill just to get some logging on for an Android library.
  5. I could write some preprocessor and inject it into the gradle build process, that would go and strip out all the debug log calls to Log.v and Log.d, but, well, that felt like something somebody else would have done already (The world being full of lots of clever people and all…)

I then took to Google, and of course came upon several StackOverflow (Good ol’ SO) questions on the problem, and some good solutions.  It took a bit of reading, and finding more questions and answers before I found the exact solution that worked for me.  With one slight small caveat, which I’ll mention later.  Read on to hear about what I ended up using as a solution.

Continue reading

How to install silc-client on Ubuntu Xenial 16.04

For many years now, the silc-client package has not been available in the standard Ubuntu apt repositories, so here’s a quick how-to on how to install the silc-client on your Ubuntu box:

First, install the dependencies to be able to compile the silc-client from source:

sudo apt-get install build-essential pkgconf libglib2.0-dev libncurses-dev

Then, download the latest silc-client source from the http://silcnet.org/ site to your Ubuntu box (Latest version is v1.1.11 – direct link here: https://downloads.sourceforge.net/project/silc/silc/client/sources/silc-client-1.1.11.tar.gz )

Extract the source file using tar:

tar zxf silc-client-1.1.11.tar.gz

Change directory into the extracted source:

cd silc-client-1.1.11

Configure the build environment:

./configure

Compile the source:

make

Then finallly, install the compiled client:

sudo make install

And that’s it, you can run the silc client now using the “silc” command:

silc -c your.favourite.silc.server.hostname -n yournick

Enjoy.

Using Microsoft Visual Studio Code as the external code editor in Unity

Yesterday during the Build 2015 developer conference, Microsoft announced and released their new editor called Visual Studio Code (or just “Code” for short).  Code is free, runs on Windows, Linux and Mac OSX.  I immediately wondered if it would be a good alternative to MonoDevelop as a code editor for use in Unity.  After a bit of fiddling, I managed to get it all working quite nicely, with proper code completion etc.  There are some caveats though, it does not work perfectly, but the caveats are easily worked around.

Here are the steps I followed on my Mac:

Continue reading

My Android development learnings so far

So I’ve been doing a lot of online courses on Javascript (and JS frameworks like Bootstrap and AngularJS), as well as a bunch of courses on Android Development.  Both from Learnable.com and Udemy.com.  I received a 1 year access to Learnable.com via New Relic in return for adding their management agent to my hosting server, and there are several freely available Android courses at Udemy, and I bought a couple when they were $10 each during the new year sale on Udemy.  The nice thing about both Udemy and Learnable, is that you receive a completion certificate once you complete a course.  I’m gathering all my certificates on my Learnings page.

I must say that Android development does seem rather straight forward, or, at least, what I’ve seen so far.  I’ve done many beginner courses, and busy going through a couple of the more intermediate and advanced courses, including a Lollipop dev course, and the way of coding is nice and concise, not a lot of guesswork involved.  I’m even using Android Studio instead of the Eclipse ADT, but still getting used to the differences.

My next step is to code up a few native applications and get them onto the Google Play Store.  Strangely enough, my biggest stumbling block so far has been to figure out under what name I want to release the apps.  Hehe.  Choosing a name is an important step!

And no, all of this learning I’m doing has nothing to do with my work-life, there is no reason I need to know these technologies for work, this is purely for self-enrichment.  I love coding, and there is not a lot of opportunity where I am at the moment, to learn or implement new things like this, so I have to keep up with it in my own time.

Vaadin Java Framework

Through the PacktPub 2014 Advent Calendar, I recently became aware of a Java framework called Vaadin.  It’s essentially a Java framework with focus on HTML5 on the frontend, it does some fancy stuff by compiling some of the frontend Java code into Javascript for presentation purposes, does all fancy data-binding between the Javascript and the backend server (compiled into a WAR for Tomcat/Glassfish, or even running on Google AppEngine) through AJAX, etc.

There’s a Vaadin Book, that I started browsing through, and the one very nice thing that I noticed about Vaadin, is that it feels very, very famliar.  The more I read and watch some of the tutorial videos, the more it feels like I’m coding an Android app.  I mean, look at this simple code snippit for creating a button, and adding an event listener to that button’s Click event:

Look familiar?

So if you are familiar with Android app development, Vaadin becomes a very small jump to creating great and rich web applications too, all totally in Java, with no need to hack around in the frontend code much, or at all.  There is an Eclipse IDE plugin that adds the typical Text/Design tabs when creating new components, allowing you to drag/drop new web components onto the a canvas, with lots of versatility.

For a step-by-step 10 minute tutorial of creating your first Vaadin app, watch their video.