July 7, 2013

Let's try to build gemrb for android on Mac OSX

I've been playing Baldur's Gate with GemRB lately.

I have found it to be pretty unstable on my Kindle Fire HD 8.9", so I want to try to run it under a debugger and see where it crashes. My first step is to try to get the code locally and build it.

I'll need GIT for that and heard that the Git OSX Installer is a reasonable way to get GIT for Mac. So I've installed that.

I had to set up a Github account (as FuguTabetai) and add SSH keys to that. Once I did that though, I was able to clone the repository (on my personal MacBook, ~/Documents/workspace):


$ git clone git@github.com:gemrb/gemrb.git

So now I have the code locally. The question is, now what to do with it. Let me take a look around. The android subdir has a great README setting out what I need to build. That includes the android-sdk (already installed due to playing around with that a few weeks ago) but I'll need to get android-ndk, mercurial (apparently) as well. Including stuff from the gemrb, I will probably also need to get cmake, make, g++, and a bunch of libraries: Zlib, Python 2.3, SDL 1.2, OpenAL, SDL_Mixer, libpng, FreeType, iconv, libVLC 2.0+.

Wow, this might take a while to get going. I have used fink in the past, but it looks like right now that is hosed. I think it would be nice to install MacPorts, but that needs the command line tools for developers to be installed. I can only find downloads for that for Mountain Lion or Lion. I'm on Snow Leopard. I found that I can download Xcode 4.2 for Snow Leopard and that includes the command line tools. So I'll do that. I think I'll need to upgrade to a newer OSX version at some point soon though.

I'm trying to do this so I can install MacPorts, and from there the other libraries that I need to build gemrb. I think this is going to take a while - I have to at least wait for the 1.8GB Xcode download to finish over the hotel internet.


Comments

Provide your email address when commenting and Gravatar will provide general portable avatars, and if you haven't signed up with them, a cute procedural avatar with their implementation of Shamus Young's Wavatars.

Re: Let's try to build gemrb for android on Mac OSX
I don't have make and friends installed. I do have XCode installed. It doesn't include gcc and those guys. You need to install Xcode 4.2 and the command line tools for that. XCode 4.2 is not available for OSX 10.6 (Snow Leopard.)

I installed https://github.com/kennethreitz/osx-gcc-installer instead.
Posted 9 years, 1 month ago by Fugu Tabetai • @wwwReply
Re: Let's try to build gemrb for android on Mac OSX
don't have a space in the path the NDK.
I had my ndk installed in "~/Android Development/android-ndk-xxxx" and that resulted in errors like:


dirname: extra operand `Development/android-ndk-r8e/ndk-build'
Try `dirname --help' for more information.
make: /Users/davee/build/core/build-local.mk: No such file or directory
make: *** No rule to make target `/Users/davee/build/core/build-local.mk'. Stop.

changing to android_development at least allowed openal to compile. continuing on...
Posted 9 years, 1 month ago by fugu Tabetai • @wwwReply
Re: Let's try to build gemrb for android on Mac OSX
You need to have at least the "tools" subdir of the android sdk on your path as well:

export PATH="$PATH:/Users/davee/android_development/adt-bundle-mac-x86_64-20130219/sdk/tools"
Posted 9 years, 1 month ago by fugu Tabetai • @wwwReply
Re: Let's try to build gemrb for android on Mac OSX
Something is wrong with the include files. Possibly related to the case insensitivity of the file system? It looks like string.h is not being properly included:


/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:77:11: error: '::memchr' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:78:11: error: '::memcmp' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:79:11: error: '::memcpy' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:80:11: error: '::memmove' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:81:11: error: '::memset' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:82:11: error: '::strcat' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:83:11: error: '::strcmp' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:84:11: error: '::strcoll' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:85:11: error: '::strcpy' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:86:11: error: '::strcspn' has not been declared
/Users/davee/android_development/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/cstring:87:11: error: '::strerror' has not been declared


etc. I have a small hello world program that I compiled and that works fine with
#include

which is what is causing the problems in the build.

I guess I'll have to look closer at the files that are being included.
Posted 9 years, 1 month ago by fugu Tabetai • @wwwReply
Re: Let's try to build gemrb for android on Mac OSX
Ok, the problem with the include files is that the local include paths are being included on the include path for the build. Basically, when does an #include instead of including the system string.h, we are including gemrb/core/System/String.h

So there are a few things I can do. This happens on OSX because the file system is case insensitive. gcc things that "string.h" and "String.h" are the same thing, and since gemrb/core/System is included on the include path, String.h is picked up first.

I think the best thing to do is to clean up the include path, and then make sure that all things we want to include that are gemrb specific are either in the main gemrb include location (gemrb/include) or are included off of the "gemrb/core" path including the subdirectory they are in:

#include "System/String.h"

I made changes to the android/build/gemrb/jni/src/Android.mk to remove all of the subdirectories from the include path. Now we just include the 3rd party dependencies include paths, "gemrb/includes", and "gemrb/core".

That gets me much further in the compile process:


/Users/davee/android_development/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: warning: ./obj/local/armeabi/libpython.so uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
/Users/davee/android_development/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs-debug/main/main/gemrb/plugins/BAMImporter/BAMImporter.o: in function GemRB::BAMImporter::GetFrameInternal(unsigned short, unsigned char, bool, unsigned char const*, GemRB::AnimationFactory*):jni/src/main/gemrb/plugins/BAMImporter/BAMImporter.cpp:152: error: undefined reference to 'GemRB::BAMSprite2D::BAMSprite2D(int, int, void const*, bool, GemRB::AnimationFactory*, GemRB::Palette*, unsigned int)'
/Users/davee/android_development/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs-debug/main/main/gemrb/plugins/SDLVideo/SDLVideo.o: in function GemRB::SDLVideoDriver::CreateSprite(int, int, int, unsigned int, unsigned int, unsigned int, unsigned int, void*, bool, int):jni/src/main/gemrb/plugins/SDLVideo/SDLVideo.cpp:336: error: undefined reference to 'GemRB::SDLSurfaceSprite2D::SDLSurfaceSprite2D(int, int, int, void*, unsigned int, unsigned int, unsigned int, unsigned int)'
/Users/davee/android_development/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs-debug/main/main/gemrb/plugins/SDLVideo/SDLVideo.o: in function GemRB::SDLVideoDriver::CreatePalettedSprite(int, int, int, void*, GemRB::Color*, bool, int):jni/src/main/gemrb/plugins/SDLVideo/SDLVideo.cpp:357: error: undefined reference to 'GemRB::SDLSurfaceSprite2D::SDLSurfaceSprite2D(int, int, int, void*, unsigned int, unsigned int, unsigned int, unsigned int)'
/Users/davee/android_development/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs-debug/main/main/gemrb/plugins/SDLVideo/SDLVideo.o: in function GemRB::SDLVideoDriver::CreatePalettedSprite(int, int, int, void*, GemRB::Color*, bool, int):jni/src/main/gemrb/plugins/SDLVideo/SDLVideo.cpp:358: error: undefined reference to 'GemRB::SDLSurfaceSprite2D::SetPalette(GemRB::Color*)'
/Users/davee/android_development/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs-debug/main/main/gemrb/plugins/SDLVideo/SDLVideo.o: in function GemRB::SDLVideoDriver::GetScreenshot(GemRB::Region):jni/src/main/gemrb/plugins/SDLVideo/SDLVideo.cpp:866: error: undefined reference to 'GemRB::SDLSurfaceSprite2D::SDLSurfaceSprite2D(int, int, int, void*, unsigned int, unsigned int, unsigned int, unsigned int)'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libmain.so] Error 1

Posted 9 years, 1 month ago by Fugu Tabetai • @wwwReply
Re: Let's try to build gemrb for android on Mac OSX
It turns out that in the time that I cloned the GemRB project and tried to build it, some updates had been made.
I did a git fetch and a git merge origin/master and that seemed to work.
I had a few other problems, but basically I think the problem is this: when I did the update, I got updated files in my project workspace. There is a build script, prep_env.sh that pulls some dependencies and copies some files to the build directory. It isn't really made to run to update after pulling a new version down, so the Android.mk that I was using was different from the GEMRB_Android.mk that was packaged for the build. So I had to re-create some changes to that (including some new cpp files so their .o files would be included and hence the functions found) as well as fix a typo that had a single character transposed.

I should think about writing a script that will just do the source code copying, or modify prep_env.sh to only re-copy the necessary GemRB source files to the build directory.

In the mean time, I'll leave this note here, and now I have to try to figure out how to debug the build on my device.
Posted 9 years, 1 month ago by Fugu Tabetai • @wwwReply
Re: Let's try to build gemrb for android on Mac OSX
Trying to run "ant debug" I had a problem: it was complaining about some files ending in -e. I think that is due to a change I made in the prep_env.sh script that left some -e files around as sed backup files. I deleted them (find . -name ".*-e" -exec rm {} ¥;) and things seemed to go well.

And by go well, I mean:


-compile:
[javac] Compiling 4 source files to /Users/davee/Documents/workspace/gemrb/android/build/gemrb/bin/classes
[javac] /Users/davee/Documents/workspace/gemrb/android/build/gemrb/src/net/sourceforge/gemrb/GemRB.java:25: cannot find symbol
[javac] symbol : class Environment
[javac] location: package android.content
[javac] import android.content.Environment;
[javac] ^
[javac] /Users/davee/Documents/workspace/gemrb/android/build/gemrb/src/net/sourceforge/gemrb/GemRB.java:52: cannot find symbol
[javac] symbol : variable Environment
[javac] location: class net.sourceforge.gemrb.GemRB
[javac] File userSuppliedConfig = new File(Environment.getExternalStoragePath().concat(gemrbHomeFolder.separator).concat("GemRB.cfg"));
[javac] ^
[javac] Note: /Users/davee/Documents/workspace/gemrb/android/build/gemrb/src/org/libsdl/app/SDLActivity.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 2 errors

Posted 9 years, 1 month ago by fugu Tabetai • @wwwReply
Re: Let's try to build gemrb for android on Mac OSX
I guess the problem is that I don't have android.jar on my classpath:


THawk:gemrb davee$ find /Users/davee/android_development/adt-bundle-mac-x86_64-20130219/ -name "android.jar"
/Users/davee/android_development/adt-bundle-mac-x86_64-20130219//sdk/platforms/android-10/android.jar
/Users/davee/android_development/adt-bundle-mac-x86_64-20130219//sdk/platforms/android-15/android.jar
/Users/davee/android_development/adt-bundle-mac-x86_64-20130219//sdk/platforms/android-17/android.jar
THawk:gemrb davee$ export CLASSPATH=/Users/davee/android_development/adt-bundle-mac-x86_64-20130219//sdk/platforms/android-15/android.jar

Hm, that didn't fix it; same errors.

ant -verbose debug:


-compile:
[javac] net/sourceforge/gemrb/GemRB.java added as net/sourceforge/gemrb/GemRB.class doesn't exist.
[javac] org/libsdl/app/SDLActivity.java added as org/libsdl/app/SDLActivity.class doesn't exist.
[javac] /Users/davee/Documents/workspace/gemrb/android/build/gemrb/gen/R.java.d skipped - don't know how to handle it
[javac] net/sourceforge/gemrb/BuildConfig.java added as net/sourceforge/gemrb/BuildConfig.class doesn't exist.
[javac] net/sourceforge/gemrb/R.java added as net/sourceforge/gemrb/R.class doesn't exist.
[javac] Compiling 4 source files to /Users/davee/Documents/workspace/gemrb/android/build/gemrb/bin/classes
[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-d'
[javac] '/Users/davee/Documents/workspace/gemrb/android/build/gemrb/bin/classes'
[javac] '-classpath'
[javac] '/Users/davee/Documents/workspace/gemrb/android/build/gemrb/bin/classes'
[javac] '-sourcepath'
[javac] '/Users/davee/Documents/workspace/gemrb/android/build/gemrb/src:/Users/davee/Documents/workspace/gemrb/android/build/gemrb/gen'
[javac] '-target'
[javac] '1.5'
[javac] '-bootclasspath'
[javac] '/Users/davee/android_development/adt-bundle-mac-x86_64-20130219/sdk/platforms/android-17/android.jar'
[javac] '-encoding'
[javac] 'UTF-8'
[javac] '-g'
[javac] '-source'
[javac] '1.5'
[javac]
[javac] The ' characters around the executable and arguments are
[javac] not part of the command.
[javac] Files to be compiled:
[javac] /Users/davee/Documents/workspace/gemrb/android/build/gemrb/src/net/sourceforge/gemrb/GemRB.java
[javac] /Users/davee/Documents/workspace/gemrb/android/build/gemrb/src/org/libsdl/app/SDLActivity.java
[javac] /Users/davee/Documents/workspace/gemrb/android/build/gemrb/gen/net/sourceforge/gemrb/BuildConfig.java
[javac] /Users/davee/Documents/workspace/gemrb/android/build/gemrb/gen/net/sourceforge/gemrb/R.java
[javac] /Users/davee/Documents/workspace/gemrb/android/build/gemrb/src/net/sourceforge/gemrb/GemRB.java:25: cannot find symbol
[javac] symbol : class Environment
[javac] location: package android.content
[javac] import android.content.Environment;
[javac] ^

(and more.)

THawk:gemrb davee$ jar -tf /Users/davee/android_development/adt-bundle-mac-x86_64-20130219/sdk/platforms/android-17/android.jar | grep Environment.class
android/os/Environment.class

Looks like an issue with the version of the SDK that I am using. So I can change the code to use android.os.Environment, or see if I can find an older version of the android.jar. I'll have to think about that for a bit.
Posted 9 years, 1 month ago by Fugu Tabetai • @wwwReply

Comments have now been turned off for this post