Facebook had to go apply some clever hacks to get its app working on Gingerbread

Mar 5, 2013 14:05 GMT  ·  By
Facebook is willing to go to great lengths to get its app working on all devices
   Facebook is willing to go to great lengths to get its app working on all devices

Facebook and Google haven't always seen eye to eye. In fact, it's fair to say that the two companies are pretty adversarial. But they do and have to work together on some things, such as the nature of the web and the tech world.

Facebook is one of the most popular apps on Android, across the world, for example. Android would take a big hit if the Facebook app were gone or worked poorly; Facebook would take an even bigger hit if it couldn't reach the hundreds of millions of Android users except via the website.

This is an even bigger problem now that Facebook is all about the mobile space. So when it hit a relatively arbitrary limit with the older Android 2.3 Gingerbread that meant it couldn't add any more features to the app, it worked alongside Google to fix it.

Facebook is one of the most complex apps for Android and one of the biggest, in terms of code. This created a rather unique problem on Gingerbread devices.

The Facebook app uses a lot of methods, over three million of them, too many for the older Android to handle.

The problem was down to the size of the buffer used to store the full list of methods used by an app at install time. Facebook worked around this by splitting the Facebook app into several components, which would be loaded separately.

But it turned out that this only fixed the issue at install time, the app still crashed when running because the same buffer with the same limits is used by running apps as well.

Loading the different components separately worked during the install process, but in the end the app still had too many methods to fit inside the buffer.

The one solution Facebook came up with was to replace the code that creates the buffer on the fly. That code is part of the Dalvik Java Virtual Machine, which underpins all Android apps.

To modify it, Facebook first had to determine where that specific piece of code is stored in memory and then proceed to overwrite it with its own code, a risky procedure at best.

But that's exactly what Facebook did, with help from Google in fact, which let it use one of its Android testing labs to run the app on 70 different phones to see if it works.

Needless to say, this was only possible because Android is open source. A closed source operating system would have required Facebook to reverse engineer the code, not a simple proposition, not to mention something that would get it thrown out of any app store.