[Original] 0 Basic learning SDL Development porting SDL2.0 to Android

Source: Internet
Author: User

In the [Original]SDL development tutorial we know how to use SDL for development under the PC, is it possible to use the same on Android? The answer is yes.

Here we are porting SDL to Android, which is based on the latest version of SDL, and is compiled in eclipse.

Development environment: Ubuntu 14.04 64-bit, Eclipse + CDT + adt,ndk

first, to the official website download http://www.libsdl.org/hg.php Download 2.0 of the source code can also be through the HG to clone the latest source code
HG Clone http://hg.libsdl.org/sdl

Ii. compiling the SDL

Go to the downloaded file sdl2-2.0.3 import android-project into Eclipse, go to the Jni folder, create a new SDL file, and SDL2-2.0.3\SRC, Sdl2-2.0.3\include, The Sdl2-2.0.3\android.mk file is copied to the android-project\jni\sdl\. The contents of the Android-project\jni\sdl\android.mk file are as follows:
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/andro ID/*.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)/SR  C/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/l OADSO/DLOPEN/*.C) $ (wildcard $ (local_path)/src/power/*.c) $ (wildcard $ (local_path)/src/power/android/*.c) $ (WI Ldcard $ (Local_path)/src/filesystem/dummy/*.c) $ (wildcard $ (local_path)/src/render/*.c) $ (wildcard $ (local_path)/s rc/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_p Rototypeslocal_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)

Configure the NDK in Eclipse, Eclipse->window->prefreneces->android->ndk.

Third, if the direct compilation will prompt the following error

file or directory  

View EGL support is above the 2.3 version, so we need to add platform support, so in the JNI directory modify the Application.mk file to specify the build platform:

if you're using the STL in your project with for more information# App_stl:= stlport_static app_abi:= Armeabi armeabi-v7ax86app_platform:= android-9
    c12>

Iv. executing ctrl+b in eclipse will compile the libsdl2.so and compile the process as follows:

 A: -: WuBuild of configuration Default forProject 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.so A: the: +Build finished (took 45s.806ms)

We'll be able to use SDL to develop it later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.