准备:
硬件
一台电脑,实验在Lenovo T430上
一个Android设备,实验在 三星S3/A7
编译环境:
Ubuntu 14.04 (ant\java等命令必须支持)
工具包:
NDK:
https://dl.google.com/android/ndk/android-ndk32-r10b-linux-x86_64.tar.bz2
SDK:https://dl.google.com/android/adt/adt-bundle-linux-x86_64-20140702.zip
SDL:http://www.libsdl.org/release/SDL2-2.0.3.tar.gz
步骤:
解压SDL:
tar -xvzf
SDL2-2.0.3.tar.gz
cd
~/Work/study/ffmpeg/SDL2-2.0.3
解压NDK,SDK
SDK路径:/opt/adrd-stuff/adt-bundle-linux-x86_64-20130514/sdk
NDK路径:/opt/adrd-stuff/android-ndk-r10b
编译过程很简单,有下面两种方式:(请认真阅读SDL2-2.0.3/README-android.txt)
1.直接编译SDL里面的一个例子:
2.自己定义一个APK
1.直接编译SDL里面的一个例子,两步:
(1).配置build-scripts/androidbuild.sh里面的两个路径,如下:
#NDKBUILD=`which
ndk-build`
NDKBUILD="/opt/adrd-stuff/android-ndk-r10b/ndk-build"
#ANDROID=`which
android`
ANDROID="/usr/local/share/adt-bundle-linux-x86_64-20140702/sdk"
(2).
直接运行命令
cd build-scripts
./androidbuild.sh
org.libsdl.testgles ../test/testgles.c
2. 自己定义一个APK
cd
android-project/jni/src/
仿照test/testgles.c,写一个含有main函数的c文件YourSourceHere.c
实验可以直接拷贝,
依次执行下面命令:
###pwd:
android-project/jni/src/
cp
../../../test/testgles.c YourSourceHere.c
cd ../jni
ln -s
/home/zhou/Work/study/ffmpeg/SDL2-2.0.3/ SDL
/opt/adrd-stuff/android-ndk-r10b/ndk-build
cd ..
ant debug
这时会在bin/
运行APK:
adb install
../SDL2-2.0.3/build/org.libsdl.testgles/bin/org.libsdl.testgles-debug.apk
adb install
../SDL2-2.0.3/android-project/bin/SDLActivity-debug.apk
这时你能看到一个旋转的彩色正方形,截图如下
遇到的问题:
NDK版本:
32bits小机用:android-ndk32-r10b-linux-x86_64.tar.bz2
64bits小机用:android-ndk64-r10b-linux-x86_64.tar.bz2
64bits编译出来的APK在S3上面运行,会有闪退的现象,
logcat提示如下:
E/dalvikvm(15444):
dlopen("/data/app-lib/org.libsdl.app-1/libSDL2.so") failed:
dlopen failed: cannot locate symbol "signal" referenced by
"libSDL2.so"...
W/dalvikvm(15444):
Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing
Lorg/libsdl/app/SDLActivity;
W/dalvikvm(15444):
Class init failed in newInstance call (Lorg/libsdl/app/SDLActivity;)
E/AndroidRuntime(15444):
Process: org.libsdl.app, PID: 15444
E/AndroidRuntime(15444):
at org.libsdl.app.SDLActivity.<clinit>(SDLActivity.java:49)
W/ActivityManager(
837): Force finishing activity org.libsdl.app/.SDLActivity