Android.mk
author Sam Lantinga <slouken@libsdl.org>
Thu, 10 Oct 2013 21:51:39 -0700
changeset 7804 1f85fb33694b
parent 7793 6463a850229d
child 8097 d4e916b1c135
permissions -rwxr-xr-x
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 LOCAL_PATH := $(call my-dir)
     2 
     3 ###########################
     4 #
     5 # SDL shared library
     6 #
     7 ###########################
     8 
     9 include $(CLEAR_VARS)
    10 
    11 LOCAL_MODULE := SDL2
    12 
    13 LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
    14 
    15 LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
    16 
    17 LOCAL_SRC_FILES := \
    18 	$(subst $(LOCAL_PATH)/,, \
    19 	$(wildcard $(LOCAL_PATH)/src/*.c) \
    20 	$(wildcard $(LOCAL_PATH)/src/audio/*.c) \
    21 	$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \
    22 	$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \
    23 	$(LOCAL_PATH)/src/atomic/SDL_atomic.c \
    24 	$(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm \
    25 	$(wildcard $(LOCAL_PATH)/src/core/android/*.c) \
    26 	$(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) \
    27 	$(wildcard $(LOCAL_PATH)/src/events/*.c) \
    28 	$(wildcard $(LOCAL_PATH)/src/file/*.c) \
    29 	$(wildcard $(LOCAL_PATH)/src/haptic/*.c) \
    30 	$(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \
    31 	$(wildcard $(LOCAL_PATH)/src/joystick/*.c) \
    32 	$(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \
    33 	$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \
    34 	$(wildcard $(LOCAL_PATH)/src/power/*.c) \
    35 	$(wildcard $(LOCAL_PATH)/src/power/android/*.c) \
    36 	$(wildcard $(LOCAL_PATH)/src/filesystem/dummy/*.c) \
    37 	$(wildcard $(LOCAL_PATH)/src/render/*.c) \
    38 	$(wildcard $(LOCAL_PATH)/src/render/*/*.c) \
    39 	$(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \
    40 	$(wildcard $(LOCAL_PATH)/src/thread/*.c) \
    41 	$(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \
    42 	$(wildcard $(LOCAL_PATH)/src/timer/*.c) \
    43 	$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \
    44 	$(wildcard $(LOCAL_PATH)/src/video/*.c) \
    45 	$(wildcard $(LOCAL_PATH)/src/video/android/*.c) \
    46     $(wildcard $(LOCAL_PATH)/src/test/*.c))
    47 
    48 LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES
    49 LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog -landroid
    50 
    51 include $(BUILD_SHARED_LIBRARY)
    52 
    53 ###########################
    54 #
    55 # SDL static library
    56 #
    57 ###########################
    58 
    59 LOCAL_MODULE := SDL2_static
    60 
    61 LOCAL_MODULE_FILENAME := libSDL2
    62 
    63 LOCAL_SRC_FILES += $(LOCAL_PATH)/src/main/android/SDL_android_main.c
    64 
    65 LOCAL_LDLIBS := 
    66 LOCAL_EXPORT_LDLIBS := -Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit -ldl -lGLESv1_CM -lGLESv2 -llog -landroid
    67 
    68 include $(BUILD_STATIC_LIBRARY)