Android Debug Vs Release Build Check in Running Code

Distinguishing Android Debug Mode Vs Release Mode

Your Android application (App) will execute in debug mode in you development environment (e.g. the Eclipse or Android Studio IDEs), and it will execute in release mode when installed from Google Play. In release mode any debug logging, StrictMode and the debugging option must be disabled. You can wrap the logging calls and StrictMode set up in code that checks for debug mode. To detect Android debug vs release mode there are two objects that expose a debug flag, ApplicationInfo (since API Level 1) and BuildConfig (recent SDK releases).

Android Debug vs Release Using ApplicationInfo Flags

With ApplicationInfo the flags field has a debug bit. It is set via the android:debuggable attribute on the application element in AndroidManifest.xml. Usually the android:debuggable attribute does not need to be present, it is set automatically by Eclipse or Android Studio. The IDEs set it to true to allow the App to be debugged. It is set to false to turn off debugging when the final APK is generated. To override the default settings add android:debuggable to the application element. Set it to true or false as required, e.g.:

To use it perform a boolean And on flags with ApplicationInfo.FLAG_DEBUGGABLE, if the result is not zero the App is in debug mode.

Android Debug vs Release Using BuildConfig.DEBUG

BuildConfig.DEBUG is set true when the App is running in the IDE. It is set false in the released APK unless android:debuggable is present and set true. Therefore  BuildConfig.DEBUG reflects the android:debuggable value unless android:debuggable is set false and the App is running in the IDE, in which case it will still be true. See the table later in the article. Continue reading

Android Icon Size – Launcher and Google Play Store

What is the Android Icon Size for an App?

For Android launcher icons you will need 6 sizes of PNG or JPG files. In pixels these are 48×48, 72×72, 96×96, 144×144, 192×192 and 512×512. The first five are for the App and the last one for when the App is deployed to the Google Play store. These are the final size of the icons and you must allow for a small margin, hence the area the icon is drawn in will be a bit smaller. For low density screens Android halves the 72×72 icon, but it is possible to include a 36×36 icon in the App for completeness, making 7 icons in total. An Android icon size table in this article summarizes all the relevant information.

144x144 XXHDPI Android Icon Size96x96 XHDPI Android Icon Size72x72 HDPI Android Icon Size48x48 MDPI Android Icon Size36x36 LDPI Android Icon Size

Android Screen Densities

The number of dots (pixels) per inch that an Android device’s screen holds determines how sharp the image on the screen looks. The more Dots Per Inch (DPI) the sharper the image. Android groups screen densities into several classes, medium, high, extra high, extra extra high and extra extra extra high! These are referred to as MDPI, HDPI, XHDPI, XXHDPI and XXXHDPI. There is also a low density class, LDPI, however not many new devices have a low density screen and thus LDPI is no longer important. MDPI is around 160 DPI, HDPI around 240 DPI, XHDPI around 320 DPI, XXHDPI around 480 DPI and XXXHDPI around 640 DPI. (LDPI is around 120 DPI). It is the screen density that determines the Android icon size used.

Android Launcher Icon Name and Location

When a new Android project is created in Eclipse or Android Studio the launcher icon file is called ic_launcher.png. You can choose the Create custom launcher icon option in the New Android Application wizard (New Project wizard in Android Studio). This allows you to configure the launcher icon based on the default Android robot, or an image file, or from several clip art images, or finally from some text. If an icon is not configured the default robot is used. The various size icons are created and placed into a folder in the projects res directory. The folders are drawable-mdpidrawable-hdpi, drawable-xhdpi and drawable-xxhdpi. It you need a low density, LDPI, icon create put a 36×36 PNG or JPG in the drawable-ldpi folder. To support Cupcake devices (API level 3) add a drawable folder and copy the 48×48 PNG or JPG file from drawable-mdpi to it. For the latest highest density displays create a drawable-xxxhdpi folder for a 192×192 icon.

The icon is referenced in the Android manifest. In the projects AndroidManifest.xml file the <application> tag has an android:icon attribute. This is set to @drawable/ic_launcher. The icon file’s name does not need to be ic_launcher, it can be called something else. For example if all the icon files for the various sizes were called my_app_icon.png then the attribute in the application tag could be set as android:icon=@drawable/my_app_icon.

Notice how the reference to the icon only needs the drawable part of the folder name. Android works out the correct density icon to use. Android will also scale one of the other density icons if an icon at a certain density is missing (though that may result in a fuzzy icon being displayed on the screen).

Android Icon Margins

The Android Operating System (OS) has evolved since it was released. This means that the icon requirements have changed over the years. The main changes are the increase in screen sizes and screen densities. Low density and medium density devices were common. Now high density and extra high density devices are the most common.

Previously it was recommend that the icon included a margin around one twelfth of the total size between the edge of the icon and the image it contained. For example the medium density icon is 48×48 pixels, one twelfth of this is 4, giving a margin of 4 pixels around the icon. This means the area available for the image is 40×40 (48 minus the margin of 4 pixels on each side).

However, the bigger screens on today’s devices gives more room for the icons so a smaller margin can be used, for example one eighteenth of the icon size. The margin allows for spaces between the icons on a screen and to allow for any drop shadows or parts of the image that stick out a little.

The High Resolution Application Icon needed for the Google Play store must be 512×512 in size. This image can have a margin to allow for padding or drop shadows, for example it could be 464×464 on the 512×512 canvas giving 48 pixels for padding and drop shadows. Again the size of the margin may depend upon the type of image being used, but the final file will be a 512×512 in size.

Android Bitmap Assets Ratios

With the 48×48 icon as baseline the 6 launcher icons have the ratios 0.75, 1, 1.5, 2, 3 and 4. These ratios apply to the screen densities. So a high density screen (HDPI) is 1.5 times a medium density screen (MDPI). I.e. 1.5 * 160 = 240. Likewise for the other densities. These ratios generally apply to all images used in an App that target different screen densities. If a bitmap is 100×100 on a medium density screen use the ratios to calculate the bitmap sizes required for other densities (75, 150, 200, 300 and 400 in this case). When generating icons and bitmap assets work at a high resolution and scale down, this prevents pixelation of the images. E.g. a canvas of 576×576 or 864×864 is good for design work. An art-board of those sizes is bigger than the biggest icon required (512×512 for the Google Play store). Even better use a vector drawing package such as Inkscape which effectively allows working at any resolution.

Android Icon Size Table

The following table summarizes all the above information.

Android Icon Size and Location for Apps
Density size Location Ratio Screen Margin
XXXHDPI 192×192 drawable-xxxhdpi 4 640 DPI 12 to 16 pixels
XXHDPI 144×144 drawable-xxhdpi 3 480 DPI 8 to 12 pixels
XHDPI 96×96 drawable-xhdpi 2 320 DPI 6 to 8 pixels
HDPI 72×72 drawable-hdpi 1.5 240 DPI 4 to 6 pixels
MDPI 48×48 drawable-mdpi 1 160 DPI 3 to 4 pixels
MDPI 48×48 drawable (Cupcake) 1 160 DPI 3 to 4 pixels
LDPI 36×36 drawable-ldpi 0.75 120 DPI 2 to 3 pixels
NA 512×512 Google Play NA NA As required

You will find a few icons on the Android Graphic Resources page, and of course many thousands more on the web.

For more information on Android Icons see the Iconography web page on the Android Developers web site.