SDL port for Android SDK/NDK 1.6

Quickly share your Android Code Snippets here...

Re: SDL port for Android SDK/NDK 1.6

Postby Beholder » Tue Nov 09, 2010 3:34 pm

pelya wrote:
Beholder wrote:Thank you! I installed Ant on Cygwin. This works well and sources compiled successfully.
I tried to compile the "Free Heroes 2" source and this was successful too! I used Crystax NDK, because STL support in your source is not complete.
Where to put game resources in an emulator to run the game?


Hey, STL support in my sources is totally complete! There's just no exceptions and no RTTI support, but that's because it's disabled in official NDK.

Did you use some additional steps to set up Cygwin environment, except for Ant? I would like to put them in readme.

If the game resources take more than 10 megabytes you're putting them to any publicly-accessible HTTP server (I've created dummy sourceforge.net project to distribute game data). Then you run ChangeAppSettings.sh and write there the URL with some description - there are lot of examples in my repo. You may write several URLs to create optional packages like enhanced game graphics, music etc.
If the game data is lesser than 10 Mb you can create dir "AndroidData" and put zipped game data there, also you should specify zip file name instead of URL for ChangeAppSettings.sh - see Ballfield demo for example.
The emulator has access to Internet from your PC, so the game should download game data without problems (although writing to emulated SD card is very slow for some reason).


Thanks, I understood.
I put the game resources on the web site and application download it to sdcard.
When I run the application I see only a black screen and a lot of errors in the adb console. The number of errors increases while the application is running. What causes such errors? Can I debug it?

My log output:
Code: Select all
I/ActivityManager(   59): Start proc com.googlecode.fheroes2 for activity com.googlecode.fheroes2/.MainActivity: pid=237 uid=10036 gids={3003, 1015}
I/WindowManager(   59): Setting rotation to 1, animFlags=1
I/ActivityManager(   59): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=34 uiMode=17 seq=4}
D/dalvikvm(  237): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl.so 0x44ede630
D/dalvikvm(  237): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl.so 0x44ede630
D/dalvikvm(  237): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_net.so 0x44ede630
D/dalvikvm(  237): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_net.so 0x44ede630
D/dalvikvm(  237): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_net.so 0x44ede630, skipping init
D/dalvikvm(  237): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_mixer.so 0x44ede630
D/dalvikvm(  237): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_mixer.so 0x44ede630
D/dalvikvm(  237): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_mixer.so 0x44ede630, skipping init
D/dalvikvm(  237): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_image.so 0x44ede630
D/dalvikvm(  237): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_image.so 0x44ede630
D/dalvikvm(  237): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_image.so 0x44ede630, skipping init
D/dalvikvm(  237): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_ttf.so 0x44ede630
D/dalvikvm(  237): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_ttf.so 0x44ede630
D/dalvikvm(  237): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_ttf.so 0x44ede630, skipping init
D/qemud   (   38): fdhandler_accept_event: accepting on fd 10
D/qemud   (   38): created client 0x150b8 listening on fd 15
D/qemud   (   38): client_fd_receive: attempting registration for service 'sensors'
D/qemud   (   38): client_fd_receive:    -> received channel id 8
D/qemud   (   38): client_registration: registration succeeded for client 8
D/qemud   (   38): fdhandler_event: disconnect on fd 15
D/dalvikvm(   59): GREF has increased to 301
I/ActivityManager(   59): Displayed activity com.googlecode.fheroes2/.MainActivity: 2452 ms (total 2452 ms)
D/libEGL  (  237): egl.cfg not found, using default config
D/libEGL  (  237): loaded /system/lib/egl/libGLES_android.so
I/libSDL  (  237): Physical screen resolution is 800x480
D/dalvikvm(  237): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libapplication.so 0x44ede630
D/dalvikvm(  237): Added shared lib /data/data/com.googlecode.fheroes2/lib/libapplication.so 0x44ede630
D/dalvikvm(  237): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libapplication.so 0x44ede630, skipping init
D/dalvikvm(  237): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_main.so 0x44ede630
D/dalvikvm(  237): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_main.so 0x44ede630
D/dalvikvm(  237): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_main.so 0x44ede630, skipping init
I/libSDL  (  237): ANDROIDAUD_OpenAudio(): app opened audio bytespersample 2 freq 22050 channels 2 bufsize 8192
I/libSDL  (  237): SDL_SetVideoMode(): application requested mode 800x480
I/libSDL  (  237): GLES_ActivateRenderer(): 800x480
I/ARMAssembler(  237): generated scanline__00000177:03010144_00000000_00000000 [ 26 ipp] (63 ins) at [0x2410e0:0x2411dc] in 4639420 ns
W/AudioFlinger(   34): write blocked for 85 msecs, 1 delayed writes, thread 0xb3d8
D/dalvikvm(   59): GC_EXPLICIT freed 8310 objects / 397800 bytes in 994ms
W/AudioFlinger(   34): write blocked for 73 msecs, 3 delayed writes, thread 0xb3d8
E/QemuSensors(  237): data__poll: len=-1, errno=9: Bad file number
E/QemuSensors(  237): data__poll: len=-1, errno=9: Bad file number
E/QemuSensors(  237): data__poll: len=-1, errno=9: Bad file number
E/QemuSensors(  237): data__poll: len=-1, errno=9: Bad file number
E/QemuSensors(  237): data__poll: len=-1, errno=9: Bad file number
E/QemuSensors(  237): data__poll: len=-1, errno=9: Bad file number
E/QemuSensors(   59): data__poll: len=-1, errno=9: Bad file number
I/ARMAssembler(  237): generated scanline__00000177:03545404_00001A07_00000000 [ 66 ipp] (91 ins) at [0x2606a8:0x260814] in 3989824 ns
E/QemuSensors(   59): data__poll: len=-1, errno=9: Bad file number
...


About Cygwin.
To setup Cygwin I used the following guide:
http://www.pocketmagic.net/?p=1332
Ant (windows binary package) should be copied to Cygwin folder and change the PATH variable to set up the path to ant executable. Nothing else. Ant using windows version of JDK correctly.
Beholder
Developer
Developer
 
Posts: 31
Joined: Tue Oct 12, 2010 6:30 pm

Top

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Tue Nov 09, 2010 6:14 pm

1. Just call exit(0) whenever you're receiving SDL_ACTIVEEVENT.
3. I'm using SdlVideoResize flag in AndroidAppSettings.sh, also I've added code to SDL to resize whole screen automatically when that's enabled - it will just modify coordinates of GLES texture before it output to screen. It works for SDL_Surface and SDL_Texture, but not for GLES.
4. This one - https://github.com/pelya/commandergenius
2,6. Mikmod - working on it.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Tue Nov 09, 2010 6:30 pm

Beholder wrote:
pelya wrote:When I run the application I see only a black screen and a lot of errors in the adb console. The number of errors increases while the application is running. What causes such errors? Can I debug it?


Code: Select all
E/QemuSensors(  237): data__poll: len=-1, errno=9: Bad file number

Only this line indicates an error, all other messages are okay.

To debug insert across the code lines like
Code: Select all
__android_log_print(ANDROID_LOG_INFO, "My App", "Image is loaded, size %d x %d", image->w, image->h);


I still not found better method for debugging.
Also if the game has some global debug function you'd better copy it to logcat using __android_log_print(). Check if the game loads all images, sounds etc
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby Beholder » Tue Nov 09, 2010 8:08 pm

I found the reasons for errors and remove them. Or rather simply activate keyboard support in the emulator. The game uses the keyboard and on the poll when there are errors.
But still nothing on the screen. Game loop goes, called Blit's and Flip. Screen is black.

I append debug messages for every action, there are no errors. What's wrong?

Code: Select all
I/ActivityManager(   62): Start proc com.googlecode.fheroes2 for activity com.googlecode.fheroes2/.MainActivity: pid=312 uid=10036 gids={3003, 1015}
I/WindowManager(   62): Setting rotation to 1, animFlags=1
I/ActivityManager(   62): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=34 uiMode=17 seq=8}
D/dalvikvm(  312): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl.so 0x44ede570
D/dalvikvm(  312): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl.so 0x44ede570
D/dalvikvm(  312): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_net.so 0x44ede570
D/dalvikvm(  312): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_net.so 0x44ede570
D/dalvikvm(  312): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_net.so 0x44ede570, skipping init
D/dalvikvm(  312): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_mixer.so 0x44ede570
D/dalvikvm(  312): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_mixer.so 0x44ede570
D/dalvikvm(  312): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_mixer.so 0x44ede570, skipping init
D/dalvikvm(  312): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_image.so 0x44ede570
D/dalvikvm(  312): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_image.so 0x44ede570
D/dalvikvm(  312): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_image.so 0x44ede570, skipping init
D/dalvikvm(  312): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_ttf.so 0x44ede570
D/dalvikvm(  312): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_ttf.so 0x44ede570
D/dalvikvm(  312): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_ttf.so 0x44ede570, skipping init
D/qemud   (   38): fdhandler_accept_event: accepting on fd 10
D/qemud   (   38): created client 0x17018 listening on fd 15
D/qemud   (   38): client_fd_receive: attempting registration for service 'sensors'
D/qemud   (   38): client_fd_receive:    -> received channel id 10
D/qemud   (   38): client_registration: registration succeeded for client 10
D/qemud   (   38): fdhandler_event: disconnect on fd 15
I/ActivityManager(   62): Displayed activity com.googlecode.fheroes2/.MainActivity: 2284 ms (total 2284 ms)
D/libEGL  (  312): egl.cfg not found, using default config
D/libEGL  (  312): loaded /system/lib/egl/libGLES_android.so
W/IInputConnectionWrapper(  118): showStatusIcon on inactive InputConnection
I/libSDL  (  312): Physical screen resolution is 800x480
D/dalvikvm(  312): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libapplication.so 0x44ede570
D/dalvikvm(  312): Added shared lib /data/data/com.googlecode.fheroes2/lib/libapplication.so 0x44ede570
D/dalvikvm(  312): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libapplication.so 0x44ede570, skipping init
D/dalvikvm(  312): Trying to load lib /data/data/com.googlecode.fheroes2/lib/libsdl_main.so 0x44ede570
D/dalvikvm(  312): Added shared lib /data/data/com.googlecode.fheroes2/lib/libsdl_main.so 0x44ede570
D/dalvikvm(  312): No JNI_OnLoad found in /data/data/com.googlecode.fheroes2/lib/libsdl_main.so 0x44ede570, skipping init
I/FreeHeroes2(  312): Starting app
I/FreeHeroes2(  312): Trying to load config file ./fheroes2.cfg...
I/FreeHeroes2(  312): File ./fheroes2.cfg found, reading!
I/libSDL  (  312): ANDROIDAUD_OpenAudio(): app opened audio bytespersample 2 freq 22050 channels 2 bufsize 8192
I/FreeHeroes2(  312): Setting video mode to 800x480, Fullscreen=1
I/libSDL  (  312): SDL_SetVideoMode(): application requested mode 800x480
I/ARMAssembler(  312): generated scanline__00000177:03010144_00000000_00000000 [ 26 ipp] (63 ins) at [0x23fd38:0x23fe34] in 2070935 ns
I/FreeHeroes2(  312): Reading agg data...
D/dalvikvm(   62): GC_EXPLICIT freed 6107 objects / 275848 bytes in 544ms
I/FreeHeroes2(  312): Loading palette...
I/FreeHeroes2(  312): Loading font...
I/FreeHeroes2(  312): Show menu
I/FreeHeroes2(  312): In main menu...
I/FreeHeroes2(  312): Preload...
I/FreeHeroes2(  312): Cursor...
I/FreeHeroes2(  312): Background...
I/FreeHeroes2(  312): Display info: display.w=800, display.h=480, sprite.w=640, sprite.h=480
I/ARMAssembler(  312): generated scanline__00000177:03545404_00001A07_00000000 [ 66 ipp] (91 ins) at [0x25fd08:0x25fe74] in 1152032 ns
I/FreeHeroes2(  312): Draws...
I/FreeHeroes2(  312): Flip1...
I/FreeHeroes2(  312): Mainmenu loop...
I/FreeHeroes2(  312): Flip1...
I/FreeHeroes2(  312): Flip1...
I/FreeHeroes2(  312): Flip1...
Beholder
Developer
Developer
 
Posts: 31
Joined: Tue Oct 12, 2010 6:30 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Wed Nov 10, 2010 10:18 am

Well, I cannot tell you anything useful, I cannot think of any reason why screen might stay black. Give me your code please, I'll try to debug it.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby akr » Wed Nov 10, 2010 11:35 am

Whats the quickest way to checkout the git repository on ubuntu? I am not familiar with git. Thx.
akr
Developer
Developer
 
Posts: 38
Joined: Mon Nov 01, 2010 10:37 pm

Top

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Wed Nov 10, 2010 4:58 pm

sudo apt-get install git
git clone <URL>
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby akr » Thu Nov 11, 2010 9:45 am

It now downloaded repository. Now it seems that there is a almost complete project directory. But src is missing, AndroidManifest.xml is missing...
I suppose I need to do a checkout...

andreas
akr
Developer
Developer
 
Posts: 38
Joined: Mon Nov 01, 2010 10:37 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Thu Nov 11, 2010 10:23 am

Please read readme.txt - the "src" is a symlink to whatever project you want to compile, you have to create it manually. AndroidManifest.xml is generated once you run ChangeAppSettings.sh - this is done to support compilation of different projects using the same Java code.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby Beholder » Thu Nov 11, 2010 11:25 pm

pelya wrote:Well, I cannot tell you anything useful, I cannot think of any reason why screen might stay black. Give me your code please, I'll try to debug it.


I downloaded latest SVN snapshot of Free Heroes 2 from http://sourceforge.net/projects/fheroes2/ and try to build it.
Nothing has changed.

I uploaded sources containing your SDL port on depositfiles.com: link
Game resources here: link

These sources not contains my debug messages. Code contain exception handling. You can use Crystax NDK to compile it. I keep the original Makefile's from original source, maybe you want to view them. I turned off support for unicode(exclude -DWITH_TTF flag), because this required gettext library.

P.S. Today I receive my new HTC Desire HD. Now I will test apps on the device. :D
Beholder
Developer
Developer
 
Posts: 31
Joined: Tue Oct 12, 2010 6:30 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Fri Nov 12, 2010 11:14 am

Hey, I've added Mikmod library to SDL_mixer, as requested by akr.

I've tried to debug SVC code, but without success - the code is too mangled. For me it crashes somewhere inside lib_svc, not in SDL code.

Beholder wrote:I uploaded sources containing your SDL port on depositfiles.com: link
Game resources here: link

Why not use some good free uploading service like http://2shared.com/ ? That depositfiles are so lame, they don't allow me to download two files at once. On the other hand, I've followed the link in the ads on their site, and it lead me here :P
I'll try to debug it ant will tell you results.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby Beholder » Fri Nov 12, 2010 11:52 am

pelya wrote:On the other hand, I've followed the link in the ads on their site, and it lead me here :P
I'll try to debug it ant will tell you results.

:lol: :lol: :lol:

Well, in the future will be using 2shared.com. I did not know this site.
Beholder
Developer
Developer
 
Posts: 31
Joined: Tue Oct 12, 2010 6:30 pm

Re: SDL port for Android SDK/NDK 1.6

Postby T-1000 » Fri Nov 12, 2010 12:16 pm

Pelya, you are doing an impressive job here. I'm really glad that you ported mikmod :)
I am still having minor issues compiling, but due to my sillyness. I am also having a black screen when running a self compiled app, but i will to fix it in a few days.
Thanks for your time and patience.
T-1000
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Nov 12, 2010 12:10 pm

Re: SDL port for Android SDK/NDK 1.6

Postby akr » Fri Nov 12, 2010 2:32 pm

Pelya, thank you very much for porting mikmod!!! Will try it as soon as my current environment which I merged from your repository works again.
For some strange reason it crashes in SDL_GetMouseState(). This worked before have your old alienblaster environment. But will come back here for mikmod asap!

andreas
akr
Developer
Developer
 
Posts: 38
Joined: Mon Nov 01, 2010 10:37 pm

Re: SDL port for Android SDK/NDK 1.6

Postby T-1000 » Fri Nov 12, 2010 3:44 pm

mmm i keep getting blank screens... it must be something with the surfaces...

i have created a basic code and no chance...

here is the code:

init SDL
Code: Select all
SDL_Surface *screen;

#define screen_w 800
#define screen_h 480
#define screen_bpp 16

void initSDL()
{
    if((SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0))
    {
        fprintf(stderr,"Could not Initialize SDL.\nError: %s\n", SDL_GetError());
        exit (-1);
    }
    screen = SDL_SetVideoMode(screen_w,screen_h,screen_bpp, SDL_HWSURFACE|SDL_DOUBLEBUF);
    if (screen == NULL)
    {
        fprintf(stderr, "Can't set the video mode. Quitting.\nError; %s\n", SDL_GetError());
        exit (1);
    }
    if(Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
    {
        fprintf(stderr,"Warning: Couldn't set 44100 Hz 16-bit audio\n: %s\n", SDL_GetError());
    }

    SDL_ShowCursor(1);
    SDL_WM_SetCaption("Martian memory", "Martian Memory");
    fprintf(stderr,"System init Ok.\n");
    fprintf(stderr,"   Entering game...\n");
}



Main
Code: Select all
#include<stdio.h>
#include<stdarg.h>
#include<string.h>
#include<stdlib.h>
#include<SDL/SDL.h>
#include<SDL_image.h>
#include<SDL_mixer.h>
#include<math.h>
#include<time.h>

#include"initSDL.h"


int main (int argc, char * argv[])
{
    initSDL();
    SDL_Surface *Stmp;
    Stmp=IMG_Load("./gfx/menubackground.png");
    SDL_BlitSurface(Stmp, NULL, screen, NULL);
    SDL_Flip(screen);
    SDL_Delay(3000);
    SDL_Quit();
    return 0;
}


Any help is appreciated :)
T-1000
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Nov 12, 2010 12:10 pm

Top
PreviousNext

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 2 guests