Chapter 4. Tools

 

In this chapter, we’ll look at two interesting tools you can use to create an Android application.

Hack 18 Removing log statements before releasing: Android v1.6+

If your application is making requests to a server, you might be using some type of log to check whether or not your requests are successful. Unfortunately, those logs don’t get removed when you build the final APK (Android application package file). Removing logs is important to keep the logcat output as clean as possible. Leaving log statements in could also expose you to unintentional disclosure of sensitive information. In this hack, I’ll show you how easy it is to remove logs for your market release.

Developers have their own technique preferences for removing logs from the final release. Some prefer doing something like the following:

if (BuildConfig.DEBUG) LOG.d(TAG, "The log msg");

From my point of view, the best way to remove logs is to use the ProGuard tool. If you’ve never used ProGuard, let me introduce it with the following quote from the Android documentation (see section 18.2):

The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apk file that is more difficult to reverse engineer.

Hack 19 Using the Hierarchy Viewer tool to remove unnecessary vie- ews: Android v1.6+