Integrate SDL into the Android platform

Source: Internet
Author: User

Network
There are a lot of articles on the road to explain how to integrate SDL into the Android platform, and I also made a look at it by myself, and finally I will organize some steps and experiences.

The following is the development environment I used this time.

-Cygwin
-
Android ndk
: Android-ndk-r4b-windows
-SDL
: 1.2.14

Step 1
Modify makefile. Minimal in SDL as follows ):

# Makefile to build the SDL Library

Prebuilt =
/Android-ndk-r4b/build/prebuilt/Windows/arm-eabi-4.4.0

Include =
-I./include
-I/android-ndk-r4b/build/platforms/Android-8/arch-arm/usr/include
Cflags =-g-O2
$ (Include)
Cc =$ (Prebuilt)/bin/ARM-Eabi-gcc
AR =$ (Prebuilt)/bin/ARM-Eabi-ar
Ranlib =
$ (Prebuilt)/bin/ARM-Eabi-ranlib

Config_h =
Include/sdl_config.h
Target =
Libsdl.
Sources =
/

Src/*. c/

Src/Audio/*. c/

Src/CDROM/*. c/

Src/cpuinfo/*. c/

Src/events/*. c/

Src/file/*. c/

Src/Joystick/*. c/

Src/stdlib/*. c/

Src/thread/*. c/

Src/Timer/*. c/

Src/Video/*. c/

Src/Audio/DSP/*. C/

Src/Audio/DMA/*. C/

Src/Video/Fbcon/*. C
/

Src/Joystick/dummy/*. c/

Src/CDROM/dummy/*. c/

Src/thread/generic/*. c/

Src/Timer/UNIX/*. C/

Src/loadso/dummy/*. c/

Objects =
$ (Shell echo $ (sources) | sed-E's,/. C,/. O, G ')

ALL:
$ (Target)

$ (Target ):
$ (Config_h) $ (objects)

$ (AR) CRV $ @ $ ^

$ (Ranlib) $ @

$ (Config_h ):
CP
$ (Config_h). Default $ (config_h)

Clean:
 
Rm-F $ (target) $ (objects)

Step 2
Modify./include/sdl_config_minimal.h)
:

# Ifndef
_ Sdl_config_minimal_h
# Define
_ Sdl_config_minimal_h

# Include
"Sdl_platform.h"

/* This
Is the minimal configuration that can be used to build SDL */

# Include
<Stdarg. h>

Typedef
Signed Char int8_t;
Typedef
Unsigned char uint8_t;
Typedef
Signed short int16_t;
Typedef
Unsigned short uint16_t;
Typedef
Signed int int32_t;
Typedef
Unsigned int uint32_t;
Typedef
Unsigned int size_t;
Typedef
Unsigned long uintptr_t;

# DefineSdl_audio_driver_oss1

# Define
Sdl_cdrom_disabled 1

# Define
Sdl_joystick_disabled 1

# Define
Sdl_loadso_disabled 1

# Define
Sdl_threads_disabled 1

# DefineSdl_timer_unix1

# DefineSdl_video_driver_fbcon1

# Define have_stdio_h 1

# Endif
/* _ Sdl_config_minimal_h */

Step
3
Based on the framebuffer settings of Android
Runtime is/dev/graphics/fb0 (Linux is/dev/fb0), so we need to modify
./Src/Video/fbcon/sdl_fbvideo.c. Set all/dev/fb0 In the example to/dev/graphics/fb0.

Step 4
Start to initialize libsdl. A, and enter the SDL root object in cygwin.

Make-F makefile. Minimal

Step 4.1
Make
Some compile errors will occur during the process. We will solve them step by step. First, compiler will tell us that some of our changes have been
(In sdl_config_minimal.h) I fixed the following:

/Android-ndk-r4b/build/platforms/Android-8/arch-arm/usr/include/stdint. h: 53:
Error: redefinition of typedef 'int8 _ t'
./Include/sdl_config_minimal.h: 32:
Note: previous declaration of 'int8 _ t' was here

Solution
The attention method of is to mark the part of the definition in sdl_config_minimal.h ):

// Typedef signed Char int8_t;
// Typedef unsigned char uint8_t;
// Typedef signed short int16_t;
// Typedef unsigned short uint16_t;
// Typedef signed int int32_t;
// Typedef unsigned int uint32_t;
// Typedef
Unsigned int size_t;
// Typedef unsigned
Long uintptr_t;

Step 4.2
Connect
Compiler considers the size of sdl_dummy_enum as invalid:

./Include/sdl_stdinc.h: 151:
Error: size of array 'sdl _ dummy_enum 'is negative

In
In this case, I will mark the first line of sdl_stdinc.h (simplified ):

// Sdl_compile_time_assert (Enum,
Sizeof (sdl_dummy_enum) = sizeof (INT ));

Step
4.3
The following error occurs: Soundcard. h cannot be found:

Src/Audio/DSP/sdl_dspaudio.c: 44: 27:
Error: SYS/Soundcard. h: no such file or directory

Because
As sys/Soundcard. h indicates the header secret under/cygwin/usr/include, we need to return to makefile. Minimal.
To Compiler ):

Include =
-I./include
-I/android-ndk-r4b/build/platforms/Android-8/arch-arm/usr/include-I/usr/include

Repair
After modification, make again.

Step 5
Succeeded.
Libsdl. A is produced under the root object.

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.