Reader small image

You're reading from  The Android Game Developer???s Handbook

Product typeBook
Published inAug 2016
Reading LevelBeginner
PublisherPackt
ISBN-139781785885860
Edition1st Edition
Languages
Right arrow
Author (1)
Avisekhar Roy
Avisekhar Roy
author image
Avisekhar Roy

Avisekhar Roy is a B.Tech engineer in computer science. He has had a passion for coding since his school days. However, he had no plans to become a game programmer. His fate landed him in the gaming industry in 2010. Since then, he fell in love with game development. Avisekhar has worked in many formats of game development environment, ranging from small companies and individual studios to corporate companies and full-scale game development studios. He recently started his own gaming start-up in 2016 and is currently working on games for the mobile platform. Avisekhar has also worked with some big companies, such as Reliance Games in India, as well as a small-scale studio called Nautilus Mobile. He is now trying to acquire a position in the gaming industry for his own venture, Funboat Games.
Read more about Avisekhar Roy

Right arrow

Chapter 9. Testing Code and Debugging

"A bug free product is a myth" is a common phrase in the development industry. A problem-free and issue-free application or any other product is rationally not possible. However, the developer can always minimize the number of bugs and issues so that the game can run with the fewest possible problems and support the most platforms with the maximum possible efficiency.

We will discuss the scope of various debugging aspects in Android game development through the following topics:

  • Android AVDs

  • Android DDMS

  • Android device debugging

  • Monitoring the memory footprint

  • Strategic placement of different debug statements

  • Exception handling in Android games

  • Debugging for Android while working with cross-platform engines

  • Best testing practices

Android AVDs


AVDs are the most significant and important part of debugging Android games. In the initial stages, the concept started with an emulator. There are a few predefined emulators that can be used to run the build on a development PC. An Android emulator provides an interface of a real-time-like device.

AVDs have a few features that virtually provide the device RAM, Android version, screen size, display dpi, keyboard, and different visual skins. Older AVDs mostly looked the same.

In the current version of Android Studio, most of the Android device categories are provided. Developers can create AVDs as per the target development platform.

The categories are as follows:

  • Android mobile phones

  • Android tablets

  • Android TVs

  • Android wearables

AVDs can be created or manipulated by the AVD manager tool provided within the Android SDK. Each and every attribute of AVD can be managed by the AVD manager. This tool can also help the developer to create a custom AVD.

Let's have a look at the attribute factors...

Android DDMS


DDMS can be used to analyze a running application for all run-time details such as memory consumption, process calls, and so on.

The main functions of Android DDMS are port providing, screen capture on a device, thread details, heap details, and Logcat processing. This service can be used for spoofing calls and messaging.

Android DDMS is widely used for device debugging. Particularly in the game development procedure, it is often used as a line-by-line debugging system. This is very useful to identify unwanted loaded objects and assets, and to track runtime exceptions:

Android DDMS can be used to carry out the following activities.

Connecting an Android device filesystem

DDMS can connect to a device filesystem and provide a file browser-based operation to copy, modify, or delete any file on the device through a PC. This method or feature, however, is not very important for Android game development.

Profiling methods

Another interesting DDMS feature is profiling or tracing matrices...

Android device testing and debugging


Android device debugging is the most important part for any Android game development process. Let's divide this topic into two sections:

  • Device testing

  • Device debugging

Device testing

The main challenge for a game developer is to run the game on a large number of different devices. These different devices include different displays, different resolutions, different Android operating system versions, different processors, and different memory capacities. Due to these reasons, Android device testing is important and has to be carried out with great effort and planning.

Normally, in a game development cycle, first-point testing is carried out by the developer. This process makes sure that the game is running on devices.

Then, the tester or a group of testers test the game on different devices from various aspects. This is the main part of device testing.

Generally, the main testing phases are divided into four parts according to game development stages:

  • Prototype...

Monitoring the memory footprint


Memory footprints are the signs and ways of using memory during runtime. From the point of game memory usage optimization, monitoring the memory footprint is very important:

  • Checking log messages

  • Checking heap updates

  • Tracking memory allocation

  • Checking overall memory usage

  • Tracking memory leaks

Checking log messages

Using log messages has been the most effective and immediate debugging technique. Message logs are very useful for tracking the program control flow and runtime object tracking.

Dalvik message log

The Dalvik message log is useful for tracking memory. Whenever garbage collection happens, the garbage collector can print the following information through Dalvik log messaging:

  • Garbage collection reason: This info reveals the reason for triggering garbage collection. The reasons can be GC_CONCURRENT, GC_FOR_MALLOC, GC_HPROF_DUMP_HEAP, GC_EXPLICIT, or GC_EXTERNAL_ALLOC.

  • Amount of memory freed: This section states the amount of memory freed by the garbage collector...

Strategic placement of different debug statements


A debug statement is the most important part of any development process. Anything and everything can be tracked and traced through debug statements. However, being a system printing call, each debug statement comes with a cost on performance, which has a direct effect on runtime FPS. This is why a strategy on the placement of debug statements is absolutely necessary.

Let's have a look at the strategies related to following categories:

  • Memory allocation

  • Tracking the object state

  • Checking the program flow

  • Tracking object values

Memory allocation

In a game development object cycle, an object should be allocated once per initialization and deallocated on destruction. However, due to manual programming mistakes, developers forget to free the memory. In this case, the garbage collector cleans the memory when it is invoked by the system automatically. This way, a lag in performance is observed.

Now, as a strategic placement to trace such mistakes, two debug...

Exception handling in Android games


Exception handling may not be a part of debugging, but it helps reduce the number of exceptions and unnecessary application crashes.

Exception handling in Android is the same as Java exception handling.

Syntax

Standard Java syntax for exception handling is as follows:

try
{
  // Handled code here
} 
catch (Exception e)
{
  // Put debug statement with exception reason
}
finally
{
  // Default instruction if any
}

The suspicious code should be put inside a try block, and the exception should be handled in a catch block. If the module requires some default task to execute, then put it in the finally block. The catch and finally blocks might not be defined always in exception handling. However, it is recommended that you process the exception in each try block failure, which is a good programming practice. This process requires you to analyze the module to find out any vulnerable chunk of code.

Here is a simple example of handling exception along with other vulnerable...

Debugging for Android while working with cross-platform engines


Modern day game programming does not generally target a single platform. Most games are cross-platform. A cross-platform game engine is very useful for this kind of development.

Most engines come with a built-in profiler and provide some features to debug the game. However, the profiler feature is completely dependent on the manufacturer of the specific game engine.

All native platforms provide complete debug information. Game engines create a wrapper to automatically switch from one platform configuration to another and display profiler details within a common user interface.

However, these cross-platform debug tools cost some extra processing and memory. In a way, they limit game resource consumption to a certain level with an error margin.

Best testing practices


There are many standards used in the Android game development industry for testing. Testing ensures correctness, stability, functional behavior, and durability after an application is published. The most common approach for Android game testing is manual testing.

However, this process is definitely not the best. As an Android developer, a unit test is always a best practice to save time and get accurate test results.

Tools and APIs

There are several tools and Android APIs that can be used to carry out the testing procedure. Some of them are inbuilt, such as Android Test Support Library, Dumpsys, Monkeyrunner, and so on.

Most of these testing tools can be triggered through the command line and run through Android Debug Bridge.

The Monkey tools create a virtual environment to populate user actions such as click, touch, swipe and so on to determine real-time result. Monkey can be run with the following command:

adb shell monkey –p <Game Package Name> <Event Count>...

Summary


Any development process is incomplete without quality and performance assurance. Testing is the phase of development where the game needs to be verified technically and logically to see whether it can perform in the real market.

The phases of testing, debugging, and profiling the game ensures the best possible quality of the game for the targeted Android platform range. Often, an Android game works on few Android devices but not on all targeted devices. The developer can identify and resolve the issues for some specific devices through a detailed testing procedure.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
The Android Game Developer???s Handbook
Published in: Aug 2016Publisher: PacktISBN-13: 9781785885860
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Avisekhar Roy

Avisekhar Roy is a B.Tech engineer in computer science. He has had a passion for coding since his school days. However, he had no plans to become a game programmer. His fate landed him in the gaming industry in 2010. Since then, he fell in love with game development. Avisekhar has worked in many formats of game development environment, ranging from small companies and individual studios to corporate companies and full-scale game development studios. He recently started his own gaming start-up in 2016 and is currently working on games for the mobile platform. Avisekhar has also worked with some big companies, such as Reliance Games in India, as well as a small-scale studio called Nautilus Mobile. He is now trying to acquire a position in the gaming industry for his own venture, Funboat Games.
Read more about Avisekhar Roy