troubleshooting android emulators on circleci

CircleCI is a very nifty cloud-hosted continuous integration tool. It allows you to write your code with the peace of mind that you have. You can setup testing for every push, every pull request, every git tag and so on. You can upload to HockeyApp or [Fabric][3]. Everything gets tested, leaving you to write the best code possible.

For device testing on CircleCI you will need to spin up an emulator, however, you can’t really spin up x86 images on the CircleCI containers because they cannot provide KVM. As such you are left with ARM emulators which are notoriously extremely slow and end up causing flakiness in testing. Here are some tools which I regularly use to troubleshoot Android Emulators on CircleCI.

styling material toolbar in android

Android Lollipop was released back in Google I/O reflecting the new Material Design philosophy. It was followed soon by the AppCompat Library updating to v21. The Library brought in a new Action Bar pattern called Toolbar which behaves more like a custom view with a promise to customize the look and feel of it instead of the quirks of the ActionBar. The Action Bar was both less customizable and hard to style. With Toolbar some of it goes away as the Toolbar behaves more like a view group and you can initialize it with various different views which previously you could not.

set background that does not resize on soft keyboard


Here is an interesting problem. Let’s say you are in a particular view, and you want to be able to set a background. You simple use the View.setBackground(Drawable) or View.setBackgroundDrawable(Drawable) call to do this. However once you do this, you realize that whenever the soft keyboard is opened it pushes your view to the top/resizes it such that your background looks squished.

blogging with octopress from 2 computers

I use Octopress to blog from multiple computers, work and home computers, sometimes Virtual Machines even. I don’t have a track of where my latest post is going to be written from.

However, recently while deploying I encountered this strange error:

## Pushing generated _deploy website
 ! [rejected]        master -> master (non-fast-forward)
 error: failed to push some refs to ''
 hint: Updates were rejected because the tip of your current branch is behind
 hint: its remote counterpart. Integrate the remote changes (e.g.
 hint: 'git pull ...') before pushing again.
 hint: See the 'Note about fast-forwards' in 'git push --help' for details.

rooting samsung galaxy s3 gt i9305 with cyanogenmod jelly bean 4 dot 2 2

After getting the 4.3 update my Samsung Galaxy S3 started having [weird battery problems][1], it was a high I moved to a custom ROM since they were a lot stable than a few years back and offered a much better stock Android experience without any bloated software than device OEMs put inside.

In this post, I shall roughly tell you how I installed a custom on my Samsung Phone.

Warning: Rooting voids the warranty of your device. We and the developers of these files are not responsible if anything happens to your device. Use this rooting guide at your own risk!

webview vulnerability in facebook android sdk embedded oauth

Reposting this from my [FB feed][4]

##TL;DR Don’t put your FB username and password within mobile apps when you don’t have the native FB app installed!

Today I learnt that the Facebook SDK for Android is very insecure. At first I thought Man in the Middle attacks on the SDK OAuth authentication process is not possible, but if you are embedding someone else’s WebView within your own App via the SDK, you can very well control them, either via Reflection, or just by modifying the SDK code coz FB makes the SDK a public download which you then compile to link in your app. If the SDK does not find the FB app installed on a user’s phone, it resorts to using the fallback mechanism of using an embedded WebView for authentication.

doing a proper github pull request

While there may be different kind of development strategies floating around the merge vs rebase git model, one thing is for sure, you would at the end of the day want a clean merge from the contributors so that it can be tracked tested and cherry-picked if it needs to. This is where pull-requests are so effective.

What is a pull-request?

From the Official Github Guide:

Pull requests let you tell others about changes you’ve pushed to a GitHub repository. Once a pull request is sent, interested parties can review the set of changes, discuss potential modifications, and even push follow-up commits if necessary.

Pull requests are useful in the shared repository model where contributors can work on different topic branches and then file a pull request to be able to initiate discussion about potential changes which does not need to affect the rest of the project.


Here is an example of a pull request I filed for Square’s Wire open source project.

android activity problem with posting runnables

A lot of times in Android you end up writing code like this:

//---- Normal Code above ---
Runnable runnable  = new Runnable() {
    public void run() {
        // Do something stupid
// Singleton Handler Manager -- not an instance one, am I smart?
HandlerManager.getInstance().postDelayed(runnable, 20000); // Run this after 20 seconds! Delay processing of data

That is, cooking up a lot of Runnables and posting them on the Handler to be run after a period of time. It happens.

As our role as developers trying to get a feature done in time, sometimes these Runnnables are the only hope. However, this Runnable introduces a potential memory leak.

optimizing google protocol buffers with wire

The concept of [Protocol Buffers][protobuf] by Google is amazing.

###Why should you use it

Protocol Buffers is a serialization strategy, much like XML or JSON. A lot of mobile apps and web services make use of JSON for passing information. However, protocol buffers are inherently compressed formats and not intented for the human eye (readability wise). You should definitely take a look at it if you feel that you are using a lot of the mobile data or if the primary target group of your app is the domain of mobile. It however, makes sense to use them for internal RPC related APIs and communication channels.