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 pelya » Mon Apr 01, 2013 8:09 pm

I've found that FFMPEG library got zero codecs compiled-in, so I've fixed that, and also added FFPlay video player to the SDL repo, to test FFMPEG (it's not very optimal - it resizes video frame in software to your screen resolution, instead of using OpenGL, it's just a test anyway). Also, I've added function SDL_ANDROID_JavaVM() that should return Java VM instance, if your JNI_OnLoad() isn't called. BTW, if you're using C++, you're probably forgot extern "C" declaration before JNI_OnLoad(), that may be the reason why it isn't called.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Top

Re: SDL port for Android SDK/NDK 1.6

Postby petersiddle » Tue Apr 02, 2013 8:24 pm

will this improve a gaming performance of my android phone
petersiddle
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Apr 02, 2013 8:18 pm

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Tue Apr 02, 2013 9:50 pm

Thanks! Now I can get the Java function called, but now it doesn't create a VideoView object, I suspect the context given (the first parameter) is not correct, I've tried with getApplicationContext() and still nothing.
BTW, I can't see the Java errors, for example, in this case there's an exception thrown but in logcat it's not shown, I have captured it and printed a message when something was thrown.

petersiddle, if your code is slow you could try to run ./build.sh with release parameter, in my case I got a significant speed improvement, and the interaction with touches was smoother.
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby TheBurek » Fri Apr 12, 2013 5:29 pm

First of all, pelya, thank you so very much for this port! I've made a couple of games using it. I even won some money competing with them, so if you're accepting donations somewhere, I'd be glad to do it (if it's even possible from this ****hole of a country I live in).

Second, I recently found out that my application switching in my new project isn't working anymore. When I switch back, I just get a black screen, but the sound is playing, and the game is still working and responding to commands (knowing where they are on screen, I can still use them). I wrestled with the GL context destruction and texture reloading a while ago and I solved it. Now, I looked at my own logs and there were no errors reported related to that. If it was the textures, I'd still be seeing single-colored rectangles floating around. So I open up LogCat, and see an endless flow of:
Code: Select all
E/BufferQueue( 1857): [SurfaceView] dequeueBuffer: SurfaceTexture has been abandoned!
E/[EGL-ERROR](15164): void __egl_platform_dequeue_buffer(egl_surface*):1269: failed to dequeue buffer from native window (0x53095ba8); err = -19, buf = 0x5198b404

This was reproduced across several different phones. And the weird thing is - several builds later, it started working again, and then a build later - same old, black screen. Do you have any clue what might this be? I did some modifications to your source, so I've been hesitant to try newer versions, but I'll try that in the meantime. Which leads me to...

Third, what would be the "correct" setup for an app that needs just the raw accelerometer data? I never seemed to figure this out, I tried all kinds of combinations (using accelerometer, using joystic, arrow keys emulation, etc.), I stared at the source and even tried modifying it to get what I wanted, but I'm assuming there was an easier way. I just need acceleromer reading (preferably as an SDL joystick, as I've already written the code to enumerate and read them), since I'm building games ground-up for this, not porting. So, no calibration, sensitivity, setting up center position, arrow keys emulation, or anything extra drawn on screen. I just need access to accel data from my C++ code (again, probably through SDL joysticks, as it (kinda) works now). Also, I want to completely hide "device configuration" from user, so this would have to be set up as the default state. Is there already a "correct" combination of settings to achieve this bare-bones accelerometer-as-joystick wrapping? Or if not, could you possibly implement such a feature?

Thank you for your time.

EDIT: I also needed launching a browser with a specified URL, so I tried it using system() call, as you wrote a page back. Internet says I just need INTERNET permission (which is already there), but looking at my logcat (and trying it out manually in terminal emu), it appears I'm required to have INTERACT_ACROSS_USERS_FULL permission. I even tried adding it to my AndroidManifest.xml, but no luck. What am I missing?
TheBurek
Freshman
Freshman
 
Posts: 6
Joined: Fri Apr 12, 2013 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Fri Apr 12, 2013 6:24 pm

I cannot tell anything about dequeueBuffer error, this may be a bug in your code or in SDL code, restoring app from background is one of the parts of SDL where I cannot be sure if it works or not. It seems to work though in OpenArena.
If you could reproduce the error in a minimal example, like test-opengl project, that would be great. Anyway, make sure you're calling SDL_GL_SwapBuffers() at least each 5 seconds, and don't sleep indefinitely somewhere in the code.

I've changed accelerometer API quite a lot lately, in the latest version of SDL it sends you raw events through joystick 1 axes 5,6,7, and also sends you a device tilt angles calculated from accelerometer using axes 0 and 1 (so that you can code ball-rolling game using only those angles). The raw events are in millimeter²/second units, so your Y or Z axis will typically be equal to 9800, and randomly fluctuate for ±500 units. You'll need to call SDL_JoystickOpen(1) somewhere in your init code, you'll also need AppUsesAccelerometer=y in your AndroidAppSettings.cfg
To prevent device config window from showing at all, set StartupMenuButtonTimeout=0 in AndroidAppSettings.cfg

If you're building your games from ground-up, I'd suggest using Unity - currently I'm the only one developing this SDL port, during my free time, I can't possibly beat such big-name thing as Unity in features, bugfixes or customer support (maybe only in price ;) ).
if you're accepting donations somewhere, I'd be glad to do it (if it's even possible from this ****hole of a country I live in).

My country isn't much better - to accept donations in foreign currency, I'll need to visit my tax agency, and somehow prove to them I'm not doing anything illegal, ideally by showing a signed paper with a wet stamp (plus it's translation), so I would rather not.
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 TheBurek » Fri Apr 12, 2013 6:44 pm

Thank you for your reply. I'll try updating from Git and rebuilding. Do you have any thoughts on the issue with launching browser and permissions? How do I solve that one?

I know about Unity, it's a really cool SDK, but for now, I like having my own portable SDL-based code, it serves me well, and I don't really have many demands from your wrapper. It already has much much more features than I actually use. For me, it's just a mean of compiling my (already written with smartphones in mind) code to APK. When I solve my issues with accelerometer and launching the browser, that's pretty much it, I probably won't even need any more updates :)
TheBurek
Freshman
Freshman
 
Posts: 6
Joined: Fri Apr 12, 2013 1:56 pm

Top

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Fri Apr 12, 2013 6:49 pm

Some new Android release probably added that permission, I remember that system() call worked just fine last year. How then Admob window launches the browser? It works at the same application context, and does not require any additional permissions, aside from INTERNET and GET_PHONE_STATE.

Edit: I've noticed Volume Up/Down buttons won't change volume while in your game, to fix that change in androidAppSettings.cfg:
RedefinedKeys="X Y NO_REMAP NO_REMAP ..." - That is, third and fourth keycode should be NO_REMAP.
Also set ResetSdlConfigForThisVersion=y so it will reset SDL config when upgrading, all keycodes are saved there, and won't be changed on upgrade by default.
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 TheBurek » Fri Apr 12, 2013 7:18 pm

I did some research and, yeah, it's related to new multiple users stuff in Android 4.2 (AFAIK). If anyone else stumbles upon this - the solution seems to be adding "--user 0" to that command line, since it somehow messes up the default value for current user, based upon this page. Not yet sure if adding that parameter will break on older versions where there is no such parameter, will update when I find out. Any #define to detect API version in native code?
TheBurek
Freshman
Freshman
 
Posts: 6
Joined: Fri Apr 12, 2013 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Fri Apr 12, 2013 7:28 pm

I've added environment variable ANDROID_VERSION - you'll need something like this:
#include <stdlib.h>
int androidVersion = 0;
if( getenv("ANDROID_VERSION") != NULL)
androidVersion = atoi(getenv("ANDROID_VERSION"));
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 TheBurek » Fri Apr 12, 2013 7:33 pm

That was fast :) Unfortunately I don't have the time to try that out now, but I'll try to combine these tommorow and report my findings here. Thank you for your support! (see? you *can* match Unity even in this regard :))
TheBurek
Freshman
Freshman
 
Posts: 6
Joined: Fri Apr 12, 2013 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby TheBurek » Sat Apr 13, 2013 7:20 pm

Ok, I've tried this new stuff. Accelerometer works just as expected, so that's great. As for launching the browser, here's what I ended up with:

Code: Select all
void openURL(const char * url)
   {
#ifdef ANDROID
      char line[1024] = {0};
      int androidVersion = 0;
      if(getenv("ANDROID_VERSION") != NULL)
         androidVersion = atoi(getenv("ANDROID_VERSION"));
      if(androidVersion >= 17) // Jelly Bean 4.2
         sprintf(line, "am start -a android.intent.action.VIEW -d '%s' --user 0", url);
      else
         sprintf(line, "am start -a android.intent.action.VIEW -d '%s'", url);
      system(line);
#else
#ifdef WIN32
      char line[1024] = {0};
      sprintf(line, "start \"\" \"%s\"", url);
      system(line);
#else
      char line[1024] = {0};
      sprintf(line, "xdg-open \"%s\"", url);
      system(line);
#endif
#endif
   }


Btw, there was an error on line 2653 in Settings.java. Version was an integer, and string was expected, so I changed it to:
Code: Select all
nativeSetEnv( "ANDROID_VERSION", Integer.toString(android.os.Build.VERSION.SDK_INT) );


With that modification, it worked like a charm. I still haven't figured out what's wrong with abandoned surfaces and black screens. If/when I solve that one, I'll post here in case someone else gets stuck on this.
TheBurek
Freshman
Freshman
 
Posts: 6
Joined: Fri Apr 12, 2013 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby TheBurek » Mon Apr 15, 2013 3:47 pm

For now, the solution seems to be to switch to blocking swap(). I still need to reload textures and VBOs and reset parameters, but it works now, no more black screen. Keeping my fingers crossed it stays that way... Btw, looking at logcats, it seems that the problem occurs when it says mGlSurfaceCreated = true on switcing back. When that's false, it comes back ok, as it (I presume) re-creates the drawing surface. I don't know how that thing works exactly, so this is just me guessing - but is there a way to force that? Re-create the surface on resume even if it doesn't appear to be necessary?
TheBurek
Freshman
Freshman
 
Posts: 6
Joined: Fri Apr 12, 2013 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby shishanjiu » Fri Apr 26, 2013 5:42 am

hi pelya,

On my android phone, when return from suspend, my app's screen is splitted to two frames, each occupied half of the screen and displayed the same thing, and the thing displayed was half of the nomal thing it should be. Why did it happen? How can I resolve it?

Image

Furthermore, if I use main menu key to swith to main interface and then click my app's icon to return to my app, it's normal. This splitting screen only happen when return from phone's suspend.

Thanks in advance.
Last edited by shishanjiu on Fri Apr 26, 2013 10:47 am, edited 1 time in total.
shishanjiu
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Sep 20, 2012 3:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby shishanjiu » Fri Apr 26, 2013 10:30 am

Another question. An apk may have some entries or functions to execute different works, and may have some icons created on desktop to launch different functions after it's installed, just like settings of Android. Could I implement this in SDL port for Android? And how? I want to create more than one icon on desktop after my apk installed. And if one of these icons is clicked, one of funtions or parameters of the app can be launched.
shishanjiu
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Sep 20, 2012 3:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Fri Apr 26, 2013 5:21 pm

shishanjiu wrote:On my android phone, when return from suspend, my app's screen is splitted to two frames

I've fixed a similar bug few months ago, it was caused by screen orientation not changing immediately to landscape during suspend, and it happened only during initialization.
Are you using latest Git revision of the SDL? On what device did you test it? Are you using software SDL screen surface or OpenGL? Can you reproduce the bug with some minimal application, Ballfield for example?
Can you add some logs to the MainActivity.onResume(), and check that isCurrentOrientationHorizontal() returns true?

shishanjiu wrote:Another question. An apk may have some entries or functions to execute different works, and may have some icons created on desktop to launch different functions after it's installed, just like settings of Android.

SDL does not support that. If you want to add that functionality, you'll need to edit Java files and AndroidManifest.xml/AndroidManifestTemplate.xml by yourself.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Top
PreviousNext

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 9 guests