diff -r 8c3cba28b1fd android-project/src/org/libsdl/app/SDLActivity.java --- a/android-project/src/org/libsdl/app/SDLActivity.java Sat Aug 12 00:04:46 2017 -0700 +++ b/android-project/src/org/libsdl/app/SDLActivity.java Sat Aug 12 10:16:08 2017 +0200 @@ -49,7 +49,8 @@ public static boolean mExitCalledFromJava; /** If shared libraries (e.g. SDL or the native application) could not be loaded. */ - public static boolean mBrokenLibraries; + public static boolean mBrokenLibraries = false; + public static String mErrorMsgBrokenLib = ""; // If we want to separate mouse and touch events. // This is only toggled in native code when a hint is set! @@ -69,15 +70,31 @@ protected static AudioTrack mAudioTrack; protected static AudioRecord mAudioRecord; + + static { + // Load shared libraries + try { + for (String lib : getLibraries()) { + System.loadLibrary(lib); + } + } catch(UnsatisfiedLinkError e) { + System.err.println(e.getMessage()); + mBrokenLibraries = true; + mErrorMsgBrokenLib = e.getMessage(); + } catch(Exception e) { + System.err.println(e.getMessage()); + mBrokenLibraries = true; + mErrorMsgBrokenLib = e.getMessage(); + } + } + + + /** * This method is called by SDL before loading the native shared libraries. - * It can be overridden to provide names of shared libraries to be loaded. - * The default implementation returns the defaults. It never returns null. - * An array returned by a new implementation must at least contain "SDL2". - * Also keep in mind that the order the libraries are loaded may matter. * @return names of shared libraries to be loaded (e.g. "SDL2", "main"). */ - protected String[] getLibraries() { + protected static String[] getLibraries() { return new String[] { "SDL2", // "SDL2_image", @@ -88,13 +105,6 @@ }; } - // Load the .so - public void loadLibraries() { - for (String lib : getLibraries()) { - System.loadLibrary(lib); - } - } - /** * This method is called by SDL before starting the native application thread. * It can be overridden to provide the arguments after the application name. @@ -117,7 +127,6 @@ mAudioTrack = null; mAudioRecord = null; mExitCalledFromJava = false; - mBrokenLibraries = false; mIsResumedCalled = false; mIsSurfaceReady = false; mHasFocus = true; @@ -136,28 +145,14 @@ SDLActivity.initialize(); // So we can call stuff from static callbacks mSingleton = this; - - // Load shared libraries - String errorMsgBrokenLib = ""; - try { - loadLibraries(); - } catch(UnsatisfiedLinkError e) { - System.err.println(e.getMessage()); - mBrokenLibraries = true; - errorMsgBrokenLib = e.getMessage(); - } catch(Exception e) { - System.err.println(e.getMessage()); - mBrokenLibraries = true; - errorMsgBrokenLib = e.getMessage(); - } - + if (mBrokenLibraries) { AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this); dlgAlert.setMessage("An error occurred while trying to start the application. Please try again and/or reinstall." + System.getProperty("line.separator") + System.getProperty("line.separator") - + "Error: " + errorMsgBrokenLib); + + "Error: " + mErrorMsgBrokenLib); dlgAlert.setTitle("SDL Error"); dlgAlert.setPositiveButton("Exit", new DialogInterface.OnClickListener() {