Skip to content

Building for Android on Linux (Ubuntu 12.04 64bit)

echolicht edited this page Mar 28, 2014 · 5 revisions

CAVEAT
This guide is written from the perspective of a first-time Linux user to describe the steps I took to publish to Android from Linux and help other Moai users by describing problems I encountered. If any of the information I give here is wrong or misleading, please feel free to correct, clarify or add missing information.

SETUP

I assume that you already have the MOAI SDK and a working Linux-host.

Follow the setup instructions on the moai-dev github and install:
  • Android NDK
  • Android ADT Tools
  • JAVA SE 6 or 7
Check if you have the necessary 32-bit libraries, or install them if not, You need:
  • lib32z1
  • lib32ncurses5
  • lib32bz2-1.0
  • libstdc++6:i386 (for adb to work)
    (I am not sure if all 4 of those are required, but without them, android build failed for me)
Export the the environment variables for
  • MOAI_BIN ("bin" directory of the Moai SDK for your platform, e.g.: export MOAI_BIN=/home/user/moai-dev/release/linux/host-sdl/x64/bin)
  • MOAI_CONFIG (directions to a Moai config, e.g.: export MOAI_BIN=/home/user/moai-dev/samples/config/)
  • ANDROID_NDK (directions to the build folder of your android ndk, e.g.: export ANDROID_NDK=/home/user/android-ndk-r9d/)
    Set them as persistent environment variables as described here:
    https://help.ubuntu.com/community/EnvironmentVariables#Persistent_environment_variables
Install the required Android platforms

Install your Android target platforms using the Android sdk manager.
I think that Android-10 is always required, but I could be wrong.

Build the Android host

You should now be able to create your Android host with ./bin/build-android.sh

POSSIBLE PROBLEMS

./build-android.sh: line 3: /home/user/.bash_profile: No such file or directory
To my knowledge, this can be ignored.


Building C object third-party/tlsf/CMakeFiles/tlsf.dir/home/user/moai-dev/3rdparty/tlsf-2.0/tlsf.c.o
/bin/sh: 1: /media/user/storage/development/android/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Permission denied
make[3]: *** [third-party/tlsf/CMakeFiles/tlsf.dir/home/user/moai-dev/3rdparty/tlsf-2.0/tlsf.c.o] Error 126
make[2]: *** [third-party/tlsf/CMakeFiles/tlsf.dir/all] Error 2

If build-android.sh is giving you "permission denied" errors like in the example above: in my case, build-android.sh always failed while the Android NDK was stored on another partition (e.g. a shared partition between Windows and Linux). Simply changing permissions on the NDK folder did not suffice, but moving the Android NDK to the main Linux partition fixed it.


Building C object third-party/tlsf/CMakeFiles/tlsf.dir/home/user/moai-dev/3rdparty/tlsf-2.0/tlsf.c.o /bin/sh: 1: /media/user/storage/development/android/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: not found
make[3]: *** [third-party/tlsf/CMakeFiles/tlsf.dir/home/user/moai-dev/3rdparty/tlsf-2.0/tlsf.c.o] Error 127
make[2]: *** [third-party/tlsf/CMakeFiles/tlsf.dir/all] Error 2

Check if the path in your ANDROID_NDK environment variable is correct. If it is, those "not found" errors as in the example above can happen if you are missing some 32-bit libraries: see "SETUP" above for a list of the required libraries.


If adb fails because of a missing library:
error while loading shared libraries: *name of library*
Install it and please add the name of the library to the list under "SETUP" above.