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 bluemonkey » Tue Feb 21, 2012 12:29 am

Hello, has someone managed to build an app under windows?, i mean using only the ndk-build script and eclipse.
I am currently using the official SDL 1.3 android port, but i would like to use this one, because of the additional features.

Thanks in advance!
bluemonkey
Freshman
Freshman
 
Posts: 2
Joined: Sat Feb 18, 2012 1:38 am

Top

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Tue Feb 21, 2012 10:44 am

I never tried Eclipse, I am using command line exclusively. You'll also need an environment that supports symbolic links, I doubt that Eclipse build system supports that.
I've heard reports that someone was successfull with Eclipse and SDL port, although that was long ago, and Eclipse itself was running on Linux.
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 slvn » Tue Feb 21, 2012 10:46 am

Hello,

It is much easier not to use eclipse and not to use winxp.


/sb
slvn
Developer
Developer
 
Posts: 33
Joined: Thu Jul 28, 2011 7:45 am

Re: SDL port for Android SDK/NDK 1.6

Postby lmak » Tue Feb 21, 2012 6:02 pm

Just to confirm, that it's indeed possible to build under eclipse (in linux though). It wasn't really straight forward, but it was possible. I even managed to debug the native code somehow using Sequoyah. Can't remember it exactly, but I think you should just import the project as "Existing Android project".

I'm using the commandline tool for daily building, so can't remember correctly.
lmak
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Jan 20, 2011 7:16 pm

Re: SDL port for Android SDK/NDK 1.6

Postby bluemonkey » Fri Feb 24, 2012 12:17 am

Thanks everyone for your answers ;). Ok, i decided to use linux for coding, using vmware and an Ubuntu image. I did it in the past to write some codecs for rockbox, and was a LOT faster than using cygwin ;).
bluemonkey
Freshman
Freshman
 
Posts: 2
Joined: Sat Feb 18, 2012 1:38 am

Re: SDL port for Android SDK/NDK 1.6

Postby OkeUwechue » Fri Feb 24, 2012 4:30 pm

lmiadowicz wrote:Hi!

Can anyone give some information about how to build ffplay.c using pelya SDL port ?


Thank you!



When you execute the 'configure' command (part of the normal ffmpeg build procedure), you'll need to append the following switch : --enable-ffplay
otherwise, the ffplay src file may not get included in the compilation.
Also make sure that you first install the following libraries : libsdl, libopencore-amrn*, libopencore-amrw*
OkeUwechue
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Feb 24, 2012 4:23 pm

Top

Re: SDL port for Android SDK/NDK 1.6

Postby george.guo » Sat Feb 25, 2012 2:11 am

Hi Pelya,

The same .apk can work on Android 2.3, but when I run it on Android 2.2, it will report below error(failed to link libapplication.so), do I need to do special configure when build apk for Android 2.2? thanks.

Syntax: [ Download ] [ Hide ]
Using c Syntax Highlighting
  1. D/dalvikvm(  246): GC_EXTERNAL_ALLOC freed 15032 objects / 360144 bytes in 84ms
  2.  
  3. I/ARMAssembler(  246): generated scanline__00000177:03010104_00009001_00000000 [119 ipp] (144 ins) at [0x298860:0x298aa0] in 2792814 ns
  4.  
  5. D/dalvikvm(  246): Trying to load lib /data/data/com.MtLua.motiontek/lib/libapplication.so 0x44e7e4d8
  6.  
  7. I/dalvikvm(  246): Unable to dlopen(/data/data/com.MtLua.motiontek/lib/libapplication.so): Cannot load library: link_image[1995]: failed to link libapplication.so
  8.  
  9. I/dalvikvm(  246):
  10.  
  11. I/System.out(  246): libSDL: error loading lib: java.lang.UnsatisfiedLinkError: Library application not found
  12.  
  13. I/System.out(  246): libSDL: loading lib /data/data/com.MtLua.motiontek/cache/libapplication.so
  14.  
  15. D/dalvikvm(  246): Trying to load lib /data/data/com.MtLua.motiontek/cache/libapplication.so 0x44e7e4d8
  16.  
  17. I/dalvikvm(  246): Unable to dlopen(/data/data/com.MtLua.motiontek/cache/libapplication.so): Cannot load library: find_library[1188]:    33 'libapplication.so' failed to load previously
  18.  
  19. I/System.out(  246): libSDL: error loading lib: java.lang.UnsatisfiedLinkError: Library /data/data/com.MtLua.motiontek/cache/libapplication.so not found
  20.  
  21. D/dalvikvm(  246): GC_FOR_MALLOC freed 689 objects / 110656 bytes in 89ms
  22.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4
george.guo
Freshman
Freshman
 
Posts: 5
Joined: Mon Dec 12, 2011 2:44 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Mon Feb 27, 2012 7:10 pm

It's strange, basic applicaitons which use SDL are running okay on Andorid 1.6 (I've just checked that in emulator).
Maybe the library is just too big to fit the memory? This happens when you're allocating large arrays statically, you may use script checkStaticDataSize.sh to check that - if the sum of last few items is over 10-15 Mb you're in trouble, because the limit for most devices is 24 Mb. That doesn't matter if you're using malloc() or new(), you can allocate as much as you wish.
If you've used some native API that is not present in SDL 1.2 you may check it with script checkMissing.sh
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 lmak » Tue Feb 28, 2012 12:26 am

pelya,
Here's a snippet to fix full screen mode on Honeycomb and Ice Cream Sandwich. This dims the softkeys (if you hide them, a single touchevent will bring the menu up again).

More info regarding to this functionality:
http://developer.android.com/reference/ ... OW_PROFILE

Feel free to use and/or modify if you think it's useful for your port!

Code: Select all
// *** HONEYCOMB / ICS FIX FOR FULLSCREEN MODE ***
      if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
         setLowProfileMode();
         mGLView.setOnSystemUiVisibilityChangeListener(
               new View.OnSystemUiVisibilityChangeListener() {
                  public void onSystemUiVisibilityChange(int visibility) {
                        android.os.Handler handler = new Handler() {
                           @Override
                           public void handleMessage(Message msg) {
                              if(msg.what == 10) {
                                 setLowProfileMode();
                              }
                           }
                        };
                        Message msg = handler.obtainMessage(10);
                        handler.sendMessageDelayed(msg,1000);
                   }                   
               }
         );
      }

   private void setLowProfileMode()
   {
       if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
         int hiddenStatusCode = android.view.View.STATUS_BAR_HIDDEN;
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            // ICS has the same constant redefined with a different name.
            hiddenStatusCode = android.view.View.SYSTEM_UI_FLAG_LOW_PROFILE;
         }
         mGLView.setSystemUiVisibility(hiddenStatusCode);
      }   
   }
lmak
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Jan 20, 2011 7:16 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Tue Feb 28, 2012 11:36 am

Thanks, I've integrated that code, although it does not have any effect on emulator (probably I did it wrong).
See MainActivity.java:742
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 lmak » Tue Feb 28, 2012 5:25 pm

On emulator there are no soft buttons. Or least I didn't find out how to put them on. :)

The code, which I posted was working on a real device. At the moment I don't have access to any >Honeycomb devices, so can't test your code. I'll let you know if I can get hold of one again.

You commented out the timer which sends the "re-dim"-request after 1 second of bringing the menu back up. This is essential, because at least my tests showed, that otherwise the bar won't dim back again after a click on it (though can be made somehow smarter, since you commented that it produces some unnecessary debug-messages).

I don't get why the aforementioned functionality isn't provided by Android by default...
lmak
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Jan 20, 2011 7:16 pm

Re: SDL port for Android SDK/NDK 1.6

Postby hgft » Wed Feb 29, 2012 9:42 am

Coach Outlet Online Sale is with imperfections which consist of cuts, scars, and scratches will exist, the grain in its organically grown problem has between one of the most considerable dietary fibers strength, and getting a last end result between one of the most considerable durability. The grain also has organically grown breathability, resulting in increased comfort using the path from the wearer.

Louis Vuitton Outlet could possibly be one of the most well-known is not necessarily one of the most ideal for you! possibly the most current quarter round shoulder bag with fluorescent color provides you a shine in the moment, desire to possess the urge to it immediately; But possibly your pores and skin color could possibly be the earth beside the handbag could possibly be one of the most make you fondle admiringly joker choice.

Louis Vuitton Outlet supply reduce, the weakening from the role, tiny haystack in slender whole body once more and again. the right way to purchase Louis Vuitton bags That's between the powerful cohesion when Cunningham lancelet find yourself isolated point, allow wind and bad weather insulation, yr pursuing year, pile of grass system earlier short increased grass blanketed with it or bi erosion.

Jennifer Garner and Ben Affleck are the proud parents of a newborn son! The 39-year-old actress gave birth to the couple's third child in Santa Monica, Calif., a source tells Us Weekly. The family's newest addition joins older sisters Violet, 6, and Seraphina, 3. “I would have thought [Ben] wanted a boy]. At first … I really thought so,” Jen, who kept the baby's gender under wraps, told Jay Leno last month.
hgft
Experienced Developer
Experienced Developer
 
Posts: 66
Joined: Tue Feb 28, 2012 9:11 am

Re: SDL port for Android SDK/NDK 1.6

Postby jeonghun » Wed Mar 14, 2012 5:53 pm

Hello. I Have a question. (Sorry for my poor English)

I tried to run very simple example code as below using your sdl-1.2 android port
Syntax: [ Download ] [ Hide ]
Using cpp Syntax Highlighting
  1. #include <stdio.h>
  2. #include <SDL.h>
  3. #include <android/log.h>
  4.  
  5. #define WIDTH 320
  6. #define HEIGHT 240
  7. #if 1
  8. #define BPP 4
  9. #define DEPTH 32
  10. #else
  11. #define BPP 2
  12. #define DEPTH 16
  13. #endif
  14.  
  15. void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
  16. {
  17.     Uint32 colour;  
  18.  
  19.     colour = SDL_MapRGB( screen->format, r, g, b );
  20.  
  21.     switch (screen->format->BytesPerPixel) {
  22.     case 2: {
  23.             Uint16 *pixmem16;
  24.             pixmem16 = (Uint16*) screen->pixels  + y + x;
  25.             *pixmem16 = colour;
  26.     }
  27.             break;
  28.  
  29.     case 4: {
  30.             Uint32 *pixmem32;
  31.             pixmem32 = (Uint32*) screen->pixels  + y + x;
  32.             *pixmem32 = colour;
  33.     }
  34.             break;
  35.     }
  36. }
  37.  
  38.  
  39. void DrawScreen(SDL_Surface* screen, int h)
  40. {
  41.     int x, y, ytimesw;
  42.  
  43.     if(SDL_MUSTLOCK(screen))
  44.     {
  45.         if(SDL_LockSurface(screen) < 0) return;
  46.     }
  47.  
  48.     for(y = 0; y < screen->h; y++ )
  49.     {
  50.         ytimesw = y*screen->pitch/BPP;
  51.         for( x = 0; x < screen->w; x++ )
  52.         {
  53.             setpixel(screen, x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h);
  54.         }
  55.     }
  56.  
  57.     if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
  58.  
  59.     SDL_Flip(screen);
  60. }
  61.  
  62.  
  63. int SDL_main(int argc, char* argv[])
  64. {
  65.     SDL_Surface *screen;
  66.     SDL_Event event;
  67.  
  68.     int keypress = 0;
  69.     int h=0;
  70.  
  71.     if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
  72.    
  73.     if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_OPENGL | SDL_SWSURFACE)))
  74.     {
  75.         SDL_Quit();
  76.         return 1;
  77.     }
  78.  
  79.     while(!keypress)
  80.     {
  81.          DrawScreen(screen,h++);
  82.          while(SDL_PollEvent(&event))
  83.          {      
  84.               switch (event.type)
  85.               {
  86.                   case SDL_QUIT:
  87.                   keypress = 1;
  88.                   break;
  89.                   case SDL_KEYDOWN:
  90.                        keypress = 1;
  91.                        break;
  92.               }
  93.          }
  94.     }
  95.  
  96.     SDL_Quit();
  97.  
  98.     return 0;
  99. }
  100.  
  101.  
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


but terminated on SDL_MUSTLOCK() or SDL_LockSurface(). logcat below

Syntax: [ Download ] [ Hide ]
  1. 03-14 16:26:19.378: I/libSDL(1317): Calling SDL_main("sdl") 
  2. 03-14 16:26:19.378: I/libSDL(1317): param 0 = "sdl" 
  3. 03-14 16:26:19.388: I/libSDL(1317): SDL_SetVideoMode(): application requested mode 320x240 OpenGL 2 HW 0 BPP 16 
  4. 03-14 16:26:19.388: A/libc(1317): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1) 


so I changed video mode (ex-do not use opengl, etc) then termicated with logcat below

Syntax: [ Download ] [ Hide ]
  1. 03-14 16:34:59.428: I/libSDL(1416): SDL_SetVideoMode(): application requested mode 320x240 OpenGL 0 HW 1 BPP 16 
  2. 03-14 16:34:59.428: E/libSDL(1416): ERROR: Setting the swap interval is not supported 
  3. 03-14 16:34:59.428: E/libSDL(1416): ERROR: Getting the swap interval is not supported 
  4. 03-14 16:34:59.428: E/libSDL(1416): ERROR: GL_GetAttribute not supported 
  5. 03-14 16:34:59.428: I/libSDL(1416): ANDROID_GL_GetProcAddress("glGetString"): 0x4087999c 
  6. 03-14 16:34:59.438: I/ARMAssembler(1416): generated scanline__00000177:03010144_00000000_00000000 [ 26 ipp] (63 ins) at [0x49a28430:0x49a2852c] in 450618 ns 
  7. 03-14 16:34:59.449: I/ARMAssembler(1416): generated scanline__00000177:03545404_00001007_00000000 [ 84 ipp] (107 ins) at [0x49a28530:0x49a286dc] in 1515990 ns 
  8. 03-14 16:34:59.458: I/ARMAssembler(1416): generated scanline__00000177:03545404_00001A07_00000000 [ 66 ipp] (91 ins) at [0x49a286e0:0x49a2884c] in 1157881 ns 
  9. 03-14 16:34:59.458: E/dalvikvm(1416): JNI ERROR (app bug): attempt to use stale local reference 0x25300001 
  10. 03-14 16:34:59.468: W/dalvikvm(1416): JNI WARNING: 0x25300001 is not a valid JNI reference 
  11. 03-14 16:34:59.468: W/dalvikvm(1416):       in Lsdl/port/android/DemoRenderer;.nativeInit:(Ljava/lang/String;Ljava/lang/String;I)V (CallIntMethod) 
  12. 03-14 16:34:59.468: I/dalvikvm(1416): "GLThread" prio=5 tid=11 RUNNABLE 
  13. 03-14 16:34:59.468: I/dalvikvm(1416):  | group="main" sCount=0 dsCount=0 obj=0x410fc360 self=0x1d47b0 
  14. 03-14 16:34:59.468: I/dalvikvm(1416):  | sysTid=1432 nice=0 sched=0/0 cgrp=default handle=1921600 
  15. 03-14 16:34:59.468: I/dalvikvm(1416):  | schedstat=( 810383849 431623227 277 ) utm=72 stm=9 core=0 
  16. 03-14 16:34:59.468: I/dalvikvm(1416):  at sdl.port.android.DemoRenderer.nativeInit(Native Method) 
  17. 03-14 16:34:59.468: I/dalvikvm(1416):  at sdl.port.android.DemoRenderer.onDrawFrame(Video.java:411) 
  18. 03-14 16:34:59.468: I/dalvikvm(1416):  at sdl.port.android.GLSurfaceView_SDL$GLThread.run(GLSurfaceView_SDL.java:995) 
  19. 03-14 16:34:59.468: E/dalvikvm(1416): VM aborting 
  20. 03-14 16:34:59.468: A/libc(1416): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1) 


I tried above things on avd(sdk provided emulator), windows. ndk r7b. (using ndk-build.cmd) andoid 4.03 target sdk
I do not use cygwin or msys. (I modified some script but not source code)

have any idea or advice for me?

Thanks in advance
jeonghun
Freshman
Freshman
 
Posts: 2
Joined: Wed Mar 14, 2012 5:13 pm

Re: SDL port for Android SDK/NDK 1.6

Postby jeonghun » Thu Mar 15, 2012 4:09 pm

jeonghun wrote:I tried above things on avd(sdk provided emulator), windows. ndk r7b. (using ndk-build.cmd) andoid 4.03 target sdk
I do not use cygwin or msys. (I modified some script but not source code)


hmm... I try to re-create project change build target from 4.03 to 2.2. then it works properly.
jeonghun
Freshman
Freshman
 
Posts: 2
Joined: Wed Mar 14, 2012 5:13 pm

Re: SDL port for Android SDK/NDK 1.6

Postby RobGlu » Sun Mar 18, 2012 4:11 pm

Hi,

I've got a problem with the background / foreground callbacks: my user-defined functions are not called when they're supposed to be.
Here's an extract of my code:

Syntax: [ Download ] [ Hide ]
Using cpp Syntax Highlighting
  1. static void appPutToBackground(void)
  2. {
  3.    __android_log_print(ANDROID_LOG_INFO, "MyApp", "appPutToBackground");
  4. }
  5.  
  6. static void appPutToForeground(void)
  7. {
  8.    __android_log_print(ANDROID_LOG_INFO, "MyApp", "appPutToForeground");
  9. }
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.    [...]
  14.    SDL_ANDROID_SetApplicationPutToBackgroundCallback(&appPutToBackground, &appPutToForeground);
  15.    [...]
  16. }
  17.  
Parsed in 0.006 seconds, using GeSHi 1.0.8.4


The log traces don't appear in the logcat when pressing home for instance, or when the app gets the focus again.
I'm using SDL 1.2 and API android-13. Same problem with android-12.

Do you guys have an idea?
RobGlu
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Mar 18, 2012 4:03 pm

Top
PreviousNext

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 10 guests