[Android] #2759: Show a message on failure to load a .so library (by Sylvain)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index f850bf5..6e1ff07 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -37,6 +37,7 @@ public class SDLActivity extends Activity {
// Keep track of the paused state
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus;
public static boolean mExitCalledFromJava;
+ public static boolean mBrokenLibraries;
// Main components
protected static SDLActivity mSingleton;
@@ -52,13 +53,19 @@ public class SDLActivity extends Activity {
protected static AudioTrack mAudioTrack;
// Load the .so
- static {
- System.loadLibrary("SDL2");
- //System.loadLibrary("SDL2_image");
- //System.loadLibrary("SDL2_mixer");
- //System.loadLibrary("SDL2_net");
- //System.loadLibrary("SDL2_ttf");
- System.loadLibrary("main");
+ public void loadLibraries() {
+ String AppLibraries[] = {
+ "SDL2",
+ // "SDL2_image",
+ // "SDL2_mixer",
+ // "SDL2_net",
+ // "SDL2_ttf",
+ "main"
+ };
+
+ for (String lib : AppLibraries) {
+ System.loadLibrary(lib);
+ }
}
/**
@@ -83,6 +90,7 @@ public class SDLActivity extends Activity {
mSDLThread = null;
mAudioTrack = null;
mExitCalledFromJava = false;
+ mBrokenLibraries = false;
mIsPaused = false;
mIsSurfaceReady = false;
mHasFocus = true;
@@ -98,6 +106,35 @@ public class SDLActivity extends Activity {
// So we can call stuff from static callbacks
mSingleton = this;
+ // Load shared libraries
+ try {
+ loadLibraries();
+ } catch(UnsatisfiedLinkError e) {
+ System.out.println(e.getMessage());
+ mBrokenLibraries = true;
+ } catch(Exception e) {
+ System.out.println(e.getMessage());
+ mBrokenLibraries = true;
+ }
+
+ if (mBrokenLibraries)
+ {
+ AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
+ dlgAlert.setMessage("An error occurred while try to start the application. Please try again and/or reinstall.");
+ dlgAlert.setTitle("SDL Error");
+ dlgAlert.setPositiveButton("EXIT",
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,int id) {
+ // if this button is clicked, close current activity
+ SDLActivity.mSingleton.finish();
+ }
+ });
+ dlgAlert.setCancelable(true);
+ dlgAlert.create().show();
+
+ return;
+ }
+
// Set up the surface
mSurface = new SDLSurface(getApplication());
@@ -119,6 +156,11 @@ public class SDLActivity extends Activity {
protected void onPause() {
Log.v("SDL", "onPause()");
super.onPause();
+
+ if (SDLActivity.mBrokenLibraries) {
+ return;
+ }
+
SDLActivity.handlePause();
}
@@ -126,6 +168,11 @@ public class SDLActivity extends Activity {
protected void onResume() {
Log.v("SDL", "onResume()");
super.onResume();
+
+ if (SDLActivity.mBrokenLibraries) {
+ return;
+ }
+
SDLActivity.handleResume();
}
@@ -135,6 +182,10 @@ public class SDLActivity extends Activity {
super.onWindowFocusChanged(hasFocus);
Log.v("SDL", "onWindowFocusChanged(): " + hasFocus);
+ if (SDLActivity.mBrokenLibraries) {
+ return;
+ }
+
SDLActivity.mHasFocus = hasFocus;
if (hasFocus) {
SDLActivity.handleResume();
@@ -145,12 +196,25 @@ public class SDLActivity extends Activity {
public void onLowMemory() {
Log.v("SDL", "onLowMemory()");
super.onLowMemory();
+
+ if (SDLActivity.mBrokenLibraries) {
+ return;
+ }
+
SDLActivity.nativeLowMemory();
}
@Override
protected void onDestroy() {
Log.v("SDL", "onDestroy()");
+
+ if (SDLActivity.mBrokenLibraries) {
+ super.onDestroy();
+ // Reset everything in case the user re opens the app
+ SDLActivity.initialize();
+ return;
+ }
+
// Send a quit message to the application
SDLActivity.mExitCalledFromJava = true;
SDLActivity.nativeQuit();
@@ -174,6 +238,11 @@ public class SDLActivity extends Activity {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
+
+ if (SDLActivity.mBrokenLibraries) {
+ return false;
+ }
+
int keyCode = event.getKeyCode();
// Ignore certain special keys so they're handled by Android
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||