Fixed bug 2146 - Enable static linking of libSDL on Android Denis Bernard This patch to Android.mk adds support for static linking of libSDL for Android applications. A patched readme with static build instructions is also provided. It does not break existing build environments setup according to the README-android.txt since the static library version will not be built in not required. The static build uses the Android NDK module system (see docs/IMPORT-MODULE.html in the NDK folder and step 5 in the instructions below). Instructions: 1. Copy the android-project directory wherever you want to keep your projects and rename it to the name of your project. 2. Create a symlink to SDL/src/main/android/SDL_android_main.c as <project>/jni/src/SDL_android_main.c 3. Rename <project>/jni/src/Android_static.mk to <project>/jni/src/Android.mk (overwrite the existing one) 4. Edit <project>/jni/src/Android.mk to include your source files 5. create and export an environment variable named NDK_MODULE_PATH that points to the parent directory of this SDL directory. e.g.: export NDK_MODULE_PATH="$PWD"/.. 6. Edit <project>/src/org/libsdl/app/SDLActivity.java and remove the call to System.loadLibrary("SDL2") line 42. 7. Run 'ndk-build' (a script provided by the NDK). This compiles the C source Although this requires an environment variable to be setup, it can be added once and for all to the main Android.mk of the project.
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
diff --git a/Android.mk b/Android.mk
index 3cb1e31..c8e67da 100755
--- a/Android.mk
+++ b/Android.mk
@@ -49,3 +49,20 @@ LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES
LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog -landroid
include $(BUILD_SHARED_LIBRARY)
+
+###########################
+#
+# SDL static library
+#
+###########################
+
+LOCAL_MODULE := SDL2_static
+
+LOCAL_MODULE_FILENAME := libSDL2
+
+LOCAL_SRC_FILES += $(LOCAL_PATH)/src/main/android/SDL_android_main.c
+
+LOCAL_LDLIBS :=
+LOCAL_EXPORT_LDLIBS := -Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit -ldl -lGLESv1_CM -lGLESv2 -llog -landroid
+
+include $(BUILD_STATIC_LIBRARY)
diff --git a/README-android.txt b/README-android.txt
index adf3f64..a161c84 100644
--- a/README-android.txt
+++ b/README-android.txt
@@ -111,6 +111,28 @@ android-project/
================================================================================
+ Build an app with static linking of libSDL
+================================================================================
+
+This build uses the Android NDK module system.
+
+Instructions:
+1. Copy the android-project directory wherever you want to keep your projects
+ and rename it to the name of your project.
+2. Rename <project>/jni/src/Android_static.mk to <project>/jni/src/Android.mk
+ (overwrite the existing one)
+3. Edit <project>/jni/src/Android.mk to include your source files
+4. create and export an environment variable named NDK_MODULE_PATH that points
+ to the parent directory of this SDL directory. e.g.:
+
+ export NDK_MODULE_PATH="$PWD"/..
+
+5. Edit <project>/src/org/libsdl/app/SDLActivity.java and remove the call to
+ System.loadLibrary("SDL2") line 42.
+6. Run 'ndk-build' (a script provided by the NDK). This compiles the C source
+
+
+================================================================================
Customizing your application name
================================================================================
diff --git a/android-project/jni/src/Android_static.mk b/android-project/jni/src/Android_static.mk
new file mode 100644
index 0000000..faed669
--- /dev/null
+++ b/android-project/jni/src/Android_static.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := main
+
+LOCAL_SRC_FILES := YourSourceHere.c
+
+LOCAL_STATIC_LIBRARIES := SDL2_static
+
+include $(BUILD_SHARED_LIBRARY)
+$(call import-module,SDL)LOCAL_PATH := $(call my-dir)