简体   繁体   中英

Compiling SDL2 for Android

I am trying to compile SDL2 for Android on Ubuntu.

I configure SDL2 with ./configure --host=arm-linux-androideabi

After compiling using ndk-build I get a series of undefined references:

Compile thumb  : SDL2-2.0.0 <= SDL_androidkeyboard.c
Compile thumb  : SDL2-2.0.0 <= SDL_androidtouch.c
Compile thumb  : SDL2-2.0.0 <= SDL_androidvideo.c
Compile thumb  : SDL2-2.0.0 <= SDL_androidwindow.c
SharedLibrary  : libSDL2-2.0.0.so
/home/ire018/Applications/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/ire018/workspace/SDLActivity/obj/local/armeabi/objs/SDL2-2.0.0/src/audio/SDL_audio.o: in function bootstrap:SDL_audio.c(.data.rel.ro+0x0): error: undefined reference to 'PULSEAUDIO_bootstrap'
/home/ire018/Applications/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/ire018/workspace/SDLActivity/obj/local/armeabi/objs/SDL2-2.0.0/src/audio/SDL_audio.o: in function bootstrap:SDL_audio.c(.data.rel.ro+0x4): error: undefined reference to 'DISKAUD_bootstrap'
/home/ire018/Applications/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/ire018/workspace/SDLActivity/obj/local/armeabi/objs/SDL2-2.0.0/src/core/android/SDL_android.o: in function Java_org_libsdl_app_SDLActivity_onNativeResize:/home/ire018/workspace/SDLActivity/jni/SDL2-2.0.0/src/core/android/SDL_android.c:148: error: undefined reference to 'Android_SetScreenResolution'
/home/ire018/Applications/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/ire018/workspace/SDLActivity/obj/local/armeabi/objs/SDL2-2.0.0/src/core/android/SDL_android.o: in function Java_org_libsdl_app_SDLActivity_onNativeKeyDown:/home/ire018/workspace/SDLActivity/jni/SDL2-2.0.0/src/core/android/SDL_android.c:155: error: undefined reference to 'Android_OnKeyDown'
/home/ire018/Applications/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/ire018/workspace/SDLActivity/obj/local/armeabi/objs/SDL2-2.0.0/src/core/android/SDL_android.o: in function Java_org_libsdl_app_SDLActivity_onNativeKeyUp:/home/ire018/workspace/SDLActivity/jni/SDL2-2.0.0/src/core/android/SDL_android.c:162: error: undefined reference to 'Android_OnKeyUp'

Any suggestions?

You don't have to use "configure" if you are using the ndk-build system.

While technically possible, cross compilation of SDL2 to Android using "configure;make" (ie the auto tools way) is probably bugged. What people do is just use the provided Android.mk files and build directly using ndk-build (see the instructions provided in Readme-android.txt under the heading "Building an app")

From a freshly uncompressed SDL archive, I propose to simply use the ndk-build command to to build the SDL for Android. Here is the command I use :

ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk \
    APP_PLATFORM=android-18

You will have to adjust the value of APP_PLATFORM for your configuration and to ensure that you use an Android API which provides GLES 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM