Tag Archives: code

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

Adventures in Unity: Making an object move one step at a time – Tetris-style

I hit a small mental block with Project X (codename for my RealGame™ that I am trying to build in Unity), so decided to try to do something a bit simpler first, and see how that goes, purely as a learning experience, getting used to Unity and its quirks.  I decided to make a Tetris clone.

At first I thought “Hey, Unity has a physics engine, Tetris blocks drop down, I can use the physics engine!” – but alas, no, that’s not the greatest idea, as you essentially need to switch off everything about the physics engine, except for gravity really, to make it work.   Too much work, and too much randomness that could creep in.   Especially if you’re using the 3D engine but presenting it in 2D, as I had intended initially.  I figured the final game could present the blocks in 3D as they drop down, maybe move the camera around a bit depending on which side of game grid the object is, etc.  So I am sticking to 3D for now.

Ah, but the reason you’re here, you want to make an object move on “step” at a time, like a tetris block moves, over time.  I just created a script for that, see it at my GitHub repo: StepObject.cs

Here’s how it works:

Here is just the beginning of the script, we make our four public variables available and initialise a couple of private variables.  Our Start() method merely checks that we have the required variables to be able start moving at startup, if so required, so if we have SecondsPerStep and a MoveDirection is set, we make the Moving private variable equal to whatever you chose in the Inspector for the StartMoving tickbox.

Here is the meat of the script, quite small actually, not very meaty at all.  In every Update, we increase the value of the Timer variable by Time.deltaTime.  We use the Timer variable to count how much time has passed since the last time the object moved.

Et voila.  Done.  Very simple actually.  To use this in a Tetris-like game, you would adjust the SecondsPerStep variable over time as the difficulty increases, lowering that value for each level gained.  You would probably start with a number of 2 seconds per step at level one.  If you create your game grid to be one unit per square, then your MoveDirection Vector would be equal to (0,-1,0).

Please give me feedback if you use this script, and let me know how things go.

Here’s the full script code:


ZendFramework 1.5.2 Released

New ZendFramework release out today, fixing three pages of bugs this time (A fair number of them on the newer Zend_Form stuff that was added in 1.5.0). Pretty impressive, the ZF team is quite busy.

So far in my experience with ZendFramework I’ve not come across any bugs that hindered my development or required me to log a bug or even have to do any workarounds for an irritation that I found in the framework, which I find comforting actually. It means that the functionality of ZF that I’m using (So far it’s quite limited to simple CMS-type websites, nothing complicated) is fairly mature, and became mature quite quickly.

Go team ZendFramework! You guys rock!

Zend Framework updated to 1.5.1

ZendFrameworkMiniLogoI received notification today that the Zend Framework was bumped to V1.5.1, with lots of fixes to the framework itself.

We (I mean Neil) used Zend Framework for the Weylandts CMS project (A great project which finally launched last week after several delays) when I worked at OgilvyInteractive (technically, I still work there, but due to health reasons, my last official working day was last Wednesday), and I’m using the framework in a freelance project I’m doing as well. I find at times, it’s great in what it achieves and how easy it is to do certain things, but other times, like the fantastic addition of the Zend_Form classes, where things are just too much of an effort to have to jump through the hoops required. I’m not fond of reinventing the wheel, and that’s what makes the Zend Framework so nice, you only use the bits and bobs you need, and you’re not tied into a huge array of restrictions like other frameworks.