Game Development Community

Torque 2D for Android Ready

by Michael Perry · in Torque 2D Beginner · 10/28/2013 (11:47 am) · 122 replies

Android port is ready for testing. If you pull latest from the development branch, you can start using it. I don't have the time to write a formal blog yet, so spread the word. Feel free to start posting bug reports based on your own Android testing.
#101
12/04/2013 (5:21 pm)
Regarding running on the eclipse ADT emulator, is it supported? Runnning on Windows, I get an error message regarding loading the openal library.

The ultimate test is always the device, but it would be nice to get the emulator running, to do some quick tests, test several configurations on virtual devices.


java.lang.UnsatisfiedLinkError: Couldn't load openal from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.garagegames.torque2d-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.garagegames.torque2d-1, /system/lib]]]: findLibrary returned null
#102
12/06/2013 (7:21 am)
If your running on x86 emulator then you will need to compile openal lib for x86. There is a binary in there i think but its broken. I originally used precompiled libs for x86, arm, etc but i kept having problems with it loading so i recompiled from source for arm. So if it will run in the emulator that is my guess. Ive never had any luck with NDK projects in the emulator.
#103
12/11/2013 (9:57 pm)
how to play a ogg sound in t2d android?
#104
12/12/2013 (5:09 am)
Ogg is not a supported format on any of T2D's platforms. From a quick look at the platform code, I didn't find any references to mp3 playback either.
#105
12/12/2013 (8:33 am)
There is a class to play mp3s. Take a look at the AndroidStreamSource class. I'm not sure if android supports ogg or not. That class is a wrapper for the Android MediaPlayer class.

Edit: It looks like according to the docs that android does support playing ogg files with the MediaPlayer class along with a bunch of other formats.

developer.android.com/guide/appendix/media-formats.html
#106
12/14/2013 (9:03 pm)
thanks Tim, and how to show a .gif?
#107
12/15/2013 (12:17 am)
@Tim

I have an error reading defining a file path, in Android. The same path definition works in Windows, did not try in Mac (iOS; I mean I am running the ADT on a Mac, deploying to a device). I followed the guide

Quote:
You need to copy all of your assets into engine/compilers/android/assets

This is the thread

www.garagegames.com/community/forums/viewthread/135811
#108
12/15/2013 (7:19 am)
@DieRich it supports the same image formats as the other platforms, with that said I dont think t2d supports gif.

@Pedro does that file path in assets match what its printing exactly and same case? Also are you up to date with the repo or are you still using the initial repo I released?
#109
12/15/2013 (12:40 pm)
@Tim

Quote:
does that file path in assets match what its printing exactly and same case?

This thread

www.garagegames.com/community/forums/viewthread/135811

has all the details. Yes, the same code has different results in Android versus Windows, in Windows I get the right path, in Android I don't.

This code

const StringTableEntry exePath = Platform::getMainDotCsDir();

does this output in Windows

read_word_file (exePath=M:/torque2d_dev/project_game)

but in Android I get an empty string

12-14 23:42:35.239: I/Torque2D(15551): [2013/12/14 23:42:35] read_word_file (exePath=)


The file path is not related to assets, it's just a path made by concatenating strings in code. Maybe defining it as related to an asset (taml file) will do the trick, since I can read all the assets (images) in Android just fine.

I am not sure if this related to Android, or just something I am doing wrong in defining the path. I will try in Mac/iOS.

Quote:
Also are you up to date with the repo or are you still using the initial repo I released?

I am using the current development branch.

#110
12/15/2013 (1:24 pm)
@Tim

The need for reading a file just came up now with the Android port of my game. This file is a text file with a list of words.

Previously, and just to avoid reading this list from a file, I defined this list of words as an array of strings in code:

char *enable_list[] = {
"aa",
"aah",
...

This list is very large, and therefore it produces a very large object file, so large that in Visual Studio/Windows it has to be compiled with the /bigobj compiler flag (in iOS, it did fine).

However, when I tried to compile that file for Android, ADT just got stuck in the compilation.

I looked online for a solution, but it seems there is none.

If you want more details, this thread has some info on gcc and /bigobj

stackoverflow.com/questions/16596876/object-file-has-too-many-sections





#111
12/16/2013 (10:39 am)
When I said check the path, I meant case mostly. windows is not case sensitive but android is. But I actually see the problem now that I reviewed your code again.

exePath will be empty on android because android reads its assets from a zip file not the file system. So paths should start with a / (hack I did so the system knows its reading from a zip) and be followed by the path as its laid out in the compilers/android/assets folder. So in the case of that thread the correct path should be /modules/games/1/files/word.txt assuming your assets directory has modules/games/1/files/word.txt.

As for your issue, you cannot load files using STL library because as I said before, you have to read the assets from a zip file. Take a look in T2DAndroidActivity.cpp and there is a function called android_LoadFile i think its called, that will call JNI functions to load the file into memory and return a buffer of the file contents along with the size of the buffer. It is your responsibility to delete this buffer after you are done with it. If your file is so large that you cannot read the entire thing into memory, then you will need to add JNI code to process it yourself. The android APIs can return a file descriptor as well instead of a buffer of the contents.
#112
12/16/2013 (10:51 am)
@Tim
Thanks !
Really helpful explanation.
#113
12/25/2013 (5:57 am)
I published my game on the google store but I pulled it as I was adviced in the chat room that com.garagegames.torque2d would not be a good domain name for it (it's the default domain name and java package name). What do?
#114
12/25/2013 (6:33 am)
You should always pick a domain related to you or your company. Do not use garagegames or t2d, as that's what we use.
#115
12/26/2013 (7:53 pm)
I found my app crashing during the splash when the phone turned off the screen to conserve battery. I got around this by changing FLAG_ALT_FOCUSABLE_IM in line 47/48 of SplashScreen.java to FLAG_KEEP_SCREEN_ON . Edit: nvm, I thought it was working but it's not..
#116
01/30/2014 (9:14 pm)
Note 3, S4, Note 8, Tab 3 and more available for testing. I work for Samsung so I'll start developing again, If anyone needs me to test anything on a Samsung device let me know. Galaxy gear as well.
#117
02/05/2014 (5:27 am)
*SOLVED*

Figured it out. Just because it shows in the jni linked folders, does not mean its included in the build. I had to edit the makefile (android.mk) in the compilers/android/jni/ folder.

---

I have a question: I've added a resource cpp file to my build of Torque 2D (the old arrayObject.cpp). It compiles fine and has been doing very well on Windows.

When I rebuild the project in Eclipse, it seems to ignore the new file. It shows up in the file list under jni but I never see it in the console log nor does the resource integrate after the build.

Is there something else that needs to be done to add the source file?
#118
02/06/2014 (7:37 am)
Yeah eclipse really only handles java. the NDK handles the C/C++ code so you have to update the android make files. Unfortunately there is no real good way of getting around that. I linked the files in eclipse so you could easily code C/C++.
#119
02/06/2014 (8:00 am)
@Glenn: I would be interested to know if those newer samsung devices handle loading better. My samsung galaxy tab 2 7.0 is a LOT slower access the apk than my nexus 7.

nexus 7 time spent is 7 seconds to read all the filenames from the apk for the sandbox demo app. it takes 38 seconds or so on my samsung galaxy tab 2.
#120
03/12/2014 (7:38 am)
i would love to help out in any possible way with the android testing, but im having trouble getting to the point of running ADT after following the setup instructions and i try to clean my project i get

ERROR: NDK path cannot contain any spaces!

not to sure what i did wrong i didn't enter a space in the address