首页 > 代码库 > [原]零基础学习SDL开发之移植SDL2.0到Android
[原]零基础学习SDL开发之移植SDL2.0到Android
在[原]SDL开发教程我们知道了如何在pc下使用SDL进行开发,在android上面是否一样可以使用呢?答案是肯定的。
下面我们进行移植SDL到Android,这里都是基于SDL最新版进行移植的,在Eclipse中编译。
开发环境:Ubuntu 14.04 64位,Eclipse + CDT + ADT,NDK
一、到官网下载http://www.libsdl.org/hg.php 下载2.0的源码也可以通过hg来clone最新的源码
hg clone http://hg.libsdl.org/SDL
二、编译SDL
进入到下载的文件SDL2-2.0.3中将android-project导入到Eclipse中,进入jni文件夹,新建一个SDL文件,将SDL2-2.0.3\src 、SDL2-2.0.3\include、SDL2-2.0.3\Android.mk文件拷贝到android-project\jni\SDL\中。
android-project\jni\SDL\Android.mk文件内容如下:
LOCAL_PATH := $(call my-dir)############################# SDL shared library############################include $(CLEAR_VARS)LOCAL_MODULE := SDL2LOCAL_C_INCLUDES := $(LOCAL_PATH)/includeLOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,, $(wildcard $(LOCAL_PATH)/src/*.c) $(wildcard $(LOCAL_PATH)/src/audio/*.c) $(wildcard $(LOCAL_PATH)/src/audio/android/*.c) $(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) $(LOCAL_PATH)/src/atomic/SDL_atomic.c $(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm $(wildcard $(LOCAL_PATH)/src/core/android/*.c) $(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) $(wildcard $(LOCAL_PATH)/src/dynapi/*.c) $(wildcard $(LOCAL_PATH)/src/events/*.c) $(wildcard $(LOCAL_PATH)/src/file/*.c) $(wildcard $(LOCAL_PATH)/src/haptic/*.c) $(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) $(wildcard $(LOCAL_PATH)/src/joystick/*.c) $(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) $(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) $(wildcard $(LOCAL_PATH)/src/power/*.c) $(wildcard $(LOCAL_PATH)/src/power/android/*.c) $(wildcard $(LOCAL_PATH)/src/filesystem/dummy/*.c) $(wildcard $(LOCAL_PATH)/src/render/*.c) $(wildcard $(LOCAL_PATH)/src/render/*/*.c) $(wildcard $(LOCAL_PATH)/src/stdlib/*.c) $(wildcard $(LOCAL_PATH)/src/thread/*.c) $(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) $(wildcard $(LOCAL_PATH)/src/timer/*.c) $(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) $(wildcard $(LOCAL_PATH)/src/video/*.c) $(wildcard $(LOCAL_PATH)/src/video/android/*.c) $(wildcard $(LOCAL_PATH)/src/test/*.c))LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPESLOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog -landroidinclude $(BUILD_SHARED_LIBRARY)############################# SDL static library############################LOCAL_MODULE := SDL2_staticLOCAL_MODULE_FILENAME := libSDL2LOCAL_SRC_FILES += $(LOCAL_PATH)/src/main/android/SDL_android_main.cLOCAL_LDLIBS := LOCAL_EXPORT_LDLIBS := -Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit -ldl -lGLESv1_CM -lGLESv2 -llog -landroidinclude $(BUILD_STATIC_LIBRARY)
在Eclipse中配置NDK, Eclipse->Window->Prefreneces->Android->NDK.
三、如果直接编译的话会提示如下错误
fatal error: EGL/egl.h: No such file or directory
查看EGL的支持是在2.3版本以上,所以我们需要添加平台的支持,所以在jni目录修改下Application.mk文件来指定编译平台:
# Uncomment this if you‘re using STL in your project# See CPLUSPLUS-SUPPORT.html in the NDK documentation for more information# APP_STL := stlport_static APP_ABI := armeabi armeabi-v7a x86APP_PLATFORM := android-9
四、在Eclipse中执行Ctrl+B,就会编译出libSDL2.so,编译过程如下:
12:14:54 **** Build of configuration Default for project Android_SDL4 ****/opt/android-ndk/ndk/ndk-build all Compile thumb : SDL2 <= SDL_assert.cCompile thumb : SDL2 <= SDL.cCompile thumb : SDL2 <= SDL_error.cCompile thumb : SDL2 <= SDL_hints.cCompile thumb : SDL2 <= SDL_log.cCompile thumb : SDL2 <= SDL_audio.cCompile thumb : SDL2 <= SDL_audiocvt.cCompile thumb : SDL2 <= SDL_audiodev.cCompile thumb : SDL2 <= SDL_audiotypecvt.cCompile thumb : SDL2 <= SDL_mixer.cCompile thumb : SDL2 <= SDL_wave.cCompile thumb : SDL2 <= SDL_androidaudio.cCompile thumb : SDL2 <= SDL_dummyaudio.cCompile thumb : SDL2 <= SDL_atomic.cCompile arm : SDL2 <= SDL_spinlock.cCompile thumb : SDL2 <= SDL_android.cCompile thumb : SDL2 <= SDL_cpuinfo.cCompile thumb : SDL2 <= SDL_dynapi.cCompile thumb : SDL2 <= SDL_clipboardevents.cCompile thumb : SDL2 <= SDL_dropevents.cCompile thumb : SDL2 <= SDL_events.cCompile thumb : SDL2 <= SDL_gesture.cCompile thumb : SDL2 <= SDL_keyboard.cCompile thumb : SDL2 <= SDL_mouse.cCompile thumb : SDL2 <= SDL_quit.cCompile thumb : SDL2 <= SDL_touch.cCompile thumb : SDL2 <= SDL_windowevents.cCompile thumb : SDL2 <= SDL_rwops.cCompile thumb : SDL2 <= SDL_haptic.cCompile thumb : SDL2 <= SDL_syshaptic.cCompile thumb : SDL2 <= SDL_gamecontroller.cCompile thumb : SDL2 <= SDL_joystick.cCompile thumb : SDL2 <= SDL_sysjoystick.cCompile thumb : SDL2 <= SDL_sysloadso.cCompile thumb : SDL2 <= SDL_power.cCompile thumb : SDL2 <= SDL_syspower.cCompile thumb : SDL2 <= SDL_sysfilesystem.cCompile thumb : SDL2 <= SDL_d3dmath.cCompile thumb : SDL2 <= SDL_render.cCompile thumb : SDL2 <= SDL_yuv_mmx.cCompile thumb : SDL2 <= SDL_yuv_sw.cCompile thumb : SDL2 <= SDL_render_d3d11.cCompile thumb : SDL2 <= SDL_render_d3d.cCompile thumb : SDL2 <= SDL_render_gles2.cCompile thumb : SDL2 <= SDL_shaders_gles2.cCompile thumb : SDL2 <= SDL_render_gles.cCompile thumb : SDL2 <= SDL_render_gl.cCompile thumb : SDL2 <= SDL_shaders_gl.cCompile thumb : SDL2 <= SDL_render_psp.cCompile thumb : SDL2 <= SDL_blendfillrect.cCompile thumb : SDL2 <= SDL_blendline.cCompile thumb : SDL2 <= SDL_blendpoint.cCompile thumb : SDL2 <= SDL_drawline.cCompile thumb : SDL2 <= SDL_drawpoint.cCompile thumb : SDL2 <= SDL_render_sw.cCompile thumb : SDL2 <= SDL_rotate.cCompile thumb : SDL2 <= SDL_getenv.cCompile thumb : SDL2 <= SDL_iconv.cCompile thumb : SDL2 <= SDL_malloc.cCompile thumb : SDL2 <= SDL_qsort.cCompile thumb : SDL2 <= SDL_stdlib.cCompile thumb : SDL2 <= SDL_string.cCompile thumb : SDL2 <= SDL_thread.cCompile thumb : SDL2 <= SDL_syscond.cCompile thumb : SDL2 <= SDL_sysmutex.cCompile thumb : SDL2 <= SDL_syssem.cCompile thumb : SDL2 <= SDL_systhread.cCompile thumb : SDL2 <= SDL_systls.cCompile thumb : SDL2 <= SDL_timer.cCompile thumb : SDL2 <= SDL_systimer.cCompile thumb : SDL2 <= SDL_blit_0.cCompile thumb : SDL2 <= SDL_blit_1.cCompile thumb : SDL2 <= SDL_blit_A.cCompile thumb : SDL2 <= SDL_blit_auto.cCompile thumb : SDL2 <= SDL_blit.cCompile thumb : SDL2 <= SDL_blit_copy.cCompile thumb : SDL2 <= SDL_blit_N.cCompile thumb : SDL2 <= SDL_blit_slow.cCompile thumb : SDL2 <= SDL_bmp.cCompile thumb : SDL2 <= SDL_clipboard.cCompile thumb : SDL2 <= SDL_egl.cCompile thumb : SDL2 <= SDL_fillrect.cCompile thumb : SDL2 <= SDL_pixels.cCompile thumb : SDL2 <= SDL_rect.cCompile thumb : SDL2 <= SDL_RLEaccel.cCompile thumb : SDL2 <= SDL_shape.cCompile thumb : SDL2 <= SDL_stretch.cCompile thumb : SDL2 <= SDL_surface.cCompile thumb : SDL2 <= SDL_video.cCompile thumb : SDL2 <= SDL_androidclipboard.cCompile thumb : SDL2 <= SDL_androidevents.cCompile thumb : SDL2 <= SDL_androidgl.cCompile thumb : SDL2 <= SDL_androidkeyboard.cCompile thumb : SDL2 <= SDL_androidtouch.cCompile thumb : SDL2 <= SDL_androidvideo.cCompile thumb : SDL2 <= SDL_androidwindow.cCompile thumb : SDL2 <= SDL_test_assert.cCompile thumb : SDL2 <= SDL_test_common.cCompile thumb : SDL2 <= SDL_test_compare.cCompile thumb : SDL2 <= SDL_test_crc32.cCompile thumb : SDL2 <= SDL_test_font.cCompile thumb : SDL2 <= SDL_test_fuzzer.cCompile thumb : SDL2 <= SDL_test_harness.cCompile thumb : SDL2 <= SDL_test_imageBlitBlend.cCompile thumb : SDL2 <= SDL_test_imageBlit.cCompile thumb : SDL2 <= SDL_test_imageFace.cCompile thumb : SDL2 <= SDL_test_imagePrimitivesBlend.cCompile thumb : SDL2 <= SDL_test_imagePrimitives.cCompile thumb : SDL2 <= SDL_test_log.cCompile thumb : SDL2 <= SDL_test_md5.cCompile thumb : SDL2 <= SDL_test_random.cSharedLibrary : libSDL2.soInstall : libSDL2.so => libs/armeabi/libSDL2.soCompile thumb : main <= SDL_android_main.cCompile thumb : main <= SDL_Lesson.cSharedLibrary : libmain.soInstall : libmain.so => libs/armeabi/libmain.so12:15:40 Build Finished (took 45s.806ms)
后面我们就可以来使用sdl进行开发了
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。