Fixed bug 2758 - Android issues with NDK r10c and API-21
authorSam Lantinga <slouken@libsdl.org>
Fri, 14 Oct 2016 06:57:55 -0700
changeset 10534dde37ddd81bc
parent 10533 cd2e0b0c7ec5
child 10535 6fa4430b1f84
Fixed bug 2758 - Android issues with NDK r10c and API-21

Sylvain

After a long time, I found out more clearly what was going wrong.

The native libraries should be built with a "APP_PLATFORM" as low as possible.
Ideally, APP_PLATFORM should be equals to the minSdkVersion of the AndroidManifest.xml
So that the application never runs on a lower APP_PLATFORM than it has been built for.

An additional good patch would be to write explicitly in "jni/Application.mk": APP_PLATFORM=android-10

(If no APP_PLATFORM is set, the "targetSdkVersion" of the AndroidManifest.xml is applied as an APP_PLATFORM to the native libraries. And currently, this is bad, because targetSdkVersion is 12, whereas minSdkLevel is 10.
And in fact, there is a warning from ndk: "Android NDK: WARNING: APP_PLATFORM android-12 is larger than android:minSdkVersion 10 in ./AndroidManifest.xml".)


to precise what happened in the initial reported test-case:
Let say the "c" code contains a call to "srand()".

with APP_PLATFORM=android-21, libSDL2.so contains a undef reference to "srand()".
with APP_PLATFORM=android-10, libSDL2.so contains a undef reference to "srand48()".

but srand() is missing on devices with APP_PLATFORM=android-10 (it was in fact replaced by srand48()).
So, if you build for android-21 (where srand() is available), you will really have a call to "srand()" and it will fail on android-10.
That was the issue. The path tried to fix this by in fact always calling srand48().


SDL patches that were applied are beneficial anyway, there are implicitly allowing they backward compatibility of using android-21 on a android-10 platform.
It can be helpful in case you want to target a higher APP_PLATFORM than minSdkVersion to have potentially access to more functions.
Eg you want to have access to GLES3 functions (or other) of "android-21". But, if dlopen() fails (on android-10), you do a fall-back to GLES2.
android-project/jni/Application.mk
include/SDL_config_android.h
src/thread/pthread/SDL_systhread.c
     1.1 --- a/android-project/jni/Application.mk	Fri Oct 14 01:04:21 2016 -0700
     1.2 +++ b/android-project/jni/Application.mk	Fri Oct 14 06:57:55 2016 -0700
     1.3 @@ -4,3 +4,7 @@
     1.4  # APP_STL := stlport_static 
     1.5  
     1.6  APP_ABI := armeabi armeabi-v7a x86
     1.7 +
     1.8 +# Min SDK level
     1.9 +APP_PLATFORM=android-10
    1.10 +
     2.1 --- a/include/SDL_config_android.h	Fri Oct 14 01:04:21 2016 -0700
     2.2 +++ b/include/SDL_config_android.h	Fri Oct 14 06:57:55 2016 -0700
     2.3 @@ -43,6 +43,7 @@
     2.4  #define HAVE_STDINT_H   1
     2.5  #define HAVE_CTYPE_H    1
     2.6  #define HAVE_MATH_H 1
     2.7 +#define HAVE_SIGNAL_H 1
     2.8  
     2.9  /* C library functions */
    2.10  #define HAVE_MALLOC 1
    2.11 @@ -75,6 +76,7 @@
    2.12  #define HAVE_STRTOULL   1
    2.13  #define HAVE_STRTOD 1
    2.14  #define HAVE_ATOI   1
    2.15 +#define HAVE_ATOF 1
    2.16  #define HAVE_STRCMP 1
    2.17  #define HAVE_STRNCMP    1
    2.18  #define HAVE_STRCASECMP 1
    2.19 @@ -101,6 +103,7 @@
    2.20  #define HAVE_SQRTF  1
    2.21  #define HAVE_TAN    1
    2.22  #define HAVE_TANF   1
    2.23 +#define HAVE_SIGACTION 1
    2.24  #define HAVE_SETJMP 1
    2.25  #define HAVE_NANOSLEEP  1
    2.26  #define HAVE_SYSCONF    1
     3.1 --- a/src/thread/pthread/SDL_systhread.c	Fri Oct 14 01:04:21 2016 -0700
     3.2 +++ b/src/thread/pthread/SDL_systhread.c	Fri Oct 14 06:57:55 2016 -0700
     3.3 @@ -122,10 +122,10 @@
     3.4  void
     3.5  SDL_SYS_SetupThread(const char *name)
     3.6  {
     3.7 -#if !defined(__ANDROID__) && !defined(__NACL__)
     3.8 +#if !defined(__NACL__)
     3.9      int i;
    3.10      sigset_t mask;
    3.11 -#endif /* !__ANDROID__ && !__NACL__ */
    3.12 +#endif /* !__NACL__ */
    3.13  
    3.14      if (name != NULL) {
    3.15          #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
    3.16 @@ -155,14 +155,14 @@
    3.17      }
    3.18  
    3.19     /* NativeClient does not yet support signals.*/
    3.20 -#if !defined(__ANDROID__) && !defined(__NACL__)
    3.21 +#if !defined(__NACL__)
    3.22      /* Mask asynchronous signals for this thread */
    3.23      sigemptyset(&mask);
    3.24      for (i = 0; sig_list[i]; ++i) {
    3.25          sigaddset(&mask, sig_list[i]);
    3.26      }
    3.27      pthread_sigmask(SIG_BLOCK, &mask, 0);
    3.28 -#endif /* !__ANDROID__ && !__NACL__ */
    3.29 +#endif /* !__NACL__ */
    3.30  
    3.31  
    3.32  #ifdef PTHREAD_CANCEL_ASYNCHRONOUS