All Things Android (Common Troubles and FAQ)

The Common Android Specific Issues

Sometimes you will find your project working perfectly well on pc, but on Android something just isn’t right. Having run into these problems more than a few times and seeing others have too I’ve compiled a list of problems and common solutions.

1. “Help! People are complaining about Black Models! But I can see the models fine on my pc/android device!”

This is a problem with terrain currently on all devices and with regular material on what seems to be older devices (specifically samsung devices) in which textures that are not perfect squares xx yy etc. Also these textures must be a power of 2. So 64x64 128x128 etc. REMEMBER! Even though they look fine on your device doesn’t mean they work for everyone.
Be SURE to use perfect squares.

If your issue is with black terrain you will have to invert your terrains alpha map (this is reportedly fixed in the upcoming 3.1).

But currently this can be easily done in gimp by opening the scenes terrain texture in your Projects Assets-Textures->terrain-alpha directory

Then follow these instructions

  1. Choose “Colors -> Components -> Decompose” from the menu and set
    “Color model” to “RGBA”.
  2. A new image is opened with all color channels (including alpha
    channel) decomposed as single layers.
  3. Select the layer “alpha” and choose “Colors -> Invert” from the menu.
  4. Choose “Colors -> Components -> Compose” from the menu, set “Color
    model” to “RGBA” and make sure the layers are correctly mapped to
    the channels (should be given if you did not reorder the layers)

2. “Help I get an Out of Memory Error when xxx Happens!”

Out of Memory Errors will occur 99% of the time due to having too large of textures. NEVER use a texture that is 10241024. 512512 should be your MAXIMUM and you should have a reason to do that. For Android using 6464 or 128128 usually does the job.

Other cases are your object count is too high or your game logic is hicupping but not causing a stack overflow.

Check your loops and be sure you’re properly de-referencing all the things if you are depending on the garbage collector. Just because you cant SEE it in the scene doesn’t mean it’s not in memory

3. “HELP the touch events aren’t working properly as mouse events!”

Be sure that you enable the "Simulate Mouse" feature for the input manager. This can be done through inputManager.setSimulateMouse(true);+
4. "I get 0 Frames Per Second!"

While this is one of the biggest issues you’ll face developing for Android I’ve come up with a few rules for myself when creating scenes and games for Android.

1. No lights. Yes it's sucks to say but lighting is just too heavy for android (crossing my fingers for this "light culling" for 3.1) but for now... 
This means that your terrains will only be able to have 3 layers as that's all that is allowed for unshaded terrains.

Luckily you won't have a lot of work as I've written quite the nifty method to turn any node into unshaded materials. Simply run this method on your root node and it will 
take care of the rest for you.

http://hastebin.com/mubuzofina.avrasm
  1. 30,000 Vertices MAX. If your scene has more than 30,000 vertices your game will suffer. It may be playable on your device but all devices will not. I use an older Galaxy Tab 2 and my rule
    is if it works there its good. Older devices will have to deal with it. But if you’re on the latest Galaxy and you’re skipping and lagging. Then other devices will be unplayable. A good scene
    will have 10-20k and if you MUST 30k should be your limit.

  2. No Filters… Though I have not tried all filters I have found that water and fog are pretty much out. If someone has success otherwise please tell me.

  3. Limit Particle Emitters to 25 particles and 5 particles per second… Your players will probably forgive your imperfect fire before a laggy game.

5. “I have errors in my MainActivity.java and I don’t know why!”

Always attempt to clean and build your project… Your android project uses a different folder for it’s reference libraries, that means your Main Activity does. By cleaning and building the project you will update the Android Project’s libraries and references, and the errors will disappear on build.

NEVER edit the files in the Mobile Project directly without a specific reason.

6. "My Game is way too big! Why is this?"
Remember... this is an Android game and people don't have terabyte hard drives and 24/7 wifi. They will want to download your game on the go and 50 megabytes is quite a lot to commit to your game.

Any larger than 50 MB you should really be a true believer in your game.

Otherwise you will definitely want to keep your file sizes as small as possible and this can get out of hand very quickly. So I’ve come up with a few rules for myself on file size.

  1. Covered before but keep your textures as small as possible. The difference between a 256x256 and 64x64 is a LOT of space. So if you have a lot of models with a lot of textures, you will
    definitely want to make your textures as small as possible.

  2. No Shadow Maps Glow maps… Trust me, you won’t be using lighting (as of now) and those things are just going to take up space. Delete them. They might make your scene look nicer in the
    scene composer but once you go to unshaded materials (see my method above)

  3. **Important tip for those who use the Scene Composer. ALWAYS LINK DO NOT ADD.

Always link the models in the scene composer. Adding the items creates an entire copy of the model in your scene. Keep your scenes under 4mb.

7. My Game Crashes When it closes/ Doesn’t close properly!

In this case you will need to add the following method to the MainActivity.java in the Important Files section of your project

@Override public void onDestroy() { super.onDestroy(); System.runFinalization(); android.os.Process.killProcess(android.os.Process.myPid()); }

8. My game is draining peoples battery/making my device too hot!

Limiting your game to 30 fps will stop the gpu from doing so much work heating the device and saving your users batter! Of course if you are going over 30 fps perhaps you could add some more
features to your game! If not congratulations on making such an efficient application!

9. “I get IllegalArgumentException: object id must be greater than zero!”

This occurs when objects are added and removed from the scene quickly. The exact cause of this error is unknown to me, but the solution is to slow down the creation and removal of objects in the scene.
5 Likes