Adding Android x86 support to Canyon Bunny

Pinterest

A couple of days ago we updated Canyon Bunny to make it runnable on x86 based Android devices. We thought it might be a good idea to show you how easy it actually is to do that with Libgdx.

The Canyon Bunny projects are still using Libgdx 0.9.6 which was the latest stable version when the book was written. So first of all, we will need to download a newer version of Libgdx as the x86 support for Android is a relatively new feature.

So let’s get started!

Download a new version of Libgdx (0.9.9 or higher!) from the offical website here: http://libgdx.badlogicgames.com/download.html.

If you’re feeling lucky, you can also grab a Nightly Build which might come with additional features and bugfixes (and/or new bugs ;-) ).

Next, extract the newly downloaded Libgdx version and apply the following steps in order to upgrade the following three Canyon Bunny projects:

  • CanyonBunny
    1. Copy libgdx-0.9.9/gdx.jar to CanyonBunny/libs/
  • CanyonBunny-android
    1. Copy libgdx-0.9.9/armeabi/libgdx.so to CanyonBunny-android/libs/armeabi/
    2. Copy libgdx-0.9.9/armeabi-v7a/libgdx.so to CanyonBunny-android/libs/armeabi-v7a/
    3. Copy libgdx-0.9.9/x86/libgdx.so to CanyonBunny-android/libgdx/x86/
    4. Copy libgdx-0.9.9/gdx-backend-android.jar to CanyonBunny-android/libs/
    5. Delete CanyonBunny-android/libs/armeabi/libandroidgl20.so
    6. Delete CanyonBunny-android/libs/armeabi-v7a/libandroidgl20.so
  • CanyonBunny-desktop
    1. Copy libgdx-0.9.9/gdx-natives.jar to CanyonBunny-desktop/libs/
    2. Copy libgdx-0.9.9/gdx-backend-lwjgl.jar to CanyonBunny-desktop/libs/
    3. Copy libgdx-0.9.9/gdx-backend-lwjgl-natives.jar to CanyonBunny-desktop/libs/
    4. Copy libgdx-0.9.9/extensions/gdx-tools/gdx-tools.jar to CanyonBunny-desktop/libs/

Note: You might also want to copy all corresponding *-sources.jar files so that Eclipse will be able to show and suggest correct variable names and javadocs for Libgdx’s classes.

Due to some internal changes between version 0.9.6 and 0.9.9+ of Libgdx there are now errors in the code that prevent you from running the game. Luckily, we only need to make two minor changes to fix them.

The first fix is to modify the file CanyonBunny-android/assets/images/uiskin.json and replace the following code (line 20-29):

com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
	default: { listBackground: default-rect, listSelection: default-select-selection, font: default-font, fontColor: white, background: default-select }
},
com.badlogic.gdx.scenes.scene2d.ui.SplitPane$SplitPaneStyle: {
	default-vertical: { handle: default-splitpane-vertical },
	default-horizontal: { handle: default-splitpane }
},
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
	default: { vScroll: default-scroll, hScrollKnob: default-round-large, background: default-rect, hScroll: default-scroll, vScrollKnob: default-round-large }
},

with this one:

com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
	default: { vScroll: default-scroll, hScrollKnob: default-round-large, background: default-rect, hScroll: default-scroll, vScrollKnob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
	default: {
		font: default-font, fontColor: white, background: default-select,
		scrollStyle: default,
		listStyle: { font: default-font, selection: default-select-selection }
	}
},

The second fix involes the error() method in our Assets class of the CanyonBunny project. The signature of this method was changed in later versions of Libgdx so we simply need to adapt our code to the new variant.

Replace the following code (line 239-242):

	@Override
	public void error (String filename, Class type, Throwable throwable) {
		Gdx.app.error(TAG, "Couldn't load asset '" + filename + "'", (Exception)throwable);
	}

with this one:

	@Override
	public void error(AssetDescriptor asset, Throwable throwable) {
		Gdx.app.error(TAG, "Couldn't load asset '" + asset.fileName + "'", (Exception)throwable);
	}

And that’s all it takes to make our beloved Canyon Bunny run on x86 based Android devices! :-)

One comment

  1. CrisM says:

    Hi,

    i have tested it and my CB works now with libgdx 0.9.9. Thank you!

    CrisM

    PS: Unfortunately I did not won the Book Give-away, so i bought it now (BTW: currently special offer on packtpub: €3.65 :-O)

Leave a Reply

Your email address will not be published. Required fields are marked *

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.