Linux下编译android SDL2

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/MoSee/article/details/81328653

linux版本CentOS7
参考:http://wiki.libsdl.org/Android

下载android-ndk

curl https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip –output android-ndk-r17b-linux-x86_64.zip
unzip android-ndk-r17b-linux-x86_64.zip

下载android-sdk

curl https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz –output android-sdk_r24.4.1.tgz
tar zxvf android-sdk_r24.4.1.tgz

安装sdk

首先查看有哪些可以安装
android list sdk -u

Packages available for installation or update: 45
1- Android SDK Tools, revision 25.2.5
2- Android SDK Platform-tools, revision 28
3- Android SDK Build-tools, revision 28.0.1
4- Documentation for Android SDK, API 24, revision 1
5- SDK Platform Android 9, API 28, revision 4
6- SDK Platform Android 8.1.0, API 27, revision 3
7- SDK Platform Android 8.0.0, API 26, revision 2
8- SDK Platform Android 7.1.1, API 25, revision 3
9- SDK Platform Android 7.0, API 24, revision 2
10- SDK Platform Android 6.0, API 23, revision 3
11- SDK Platform Android 5.1.1, API 22, revision 2
12- SDK Platform Android 5.0.1, API 21, revision 2
13- SDK Platform Android 4.4W.2, API 20, revision 2
14- SDK Platform Android 4.4.2, API 19, revision 4
15- SDK Platform Android 4.3.1, API 18, revision 3
16- SDK Platform Android 4.2.2, API 17, revision 3
17- SDK Platform Android 4.1.2, API 16, revision 5
18- SDK Platform Android 4.0.3, API 15, revision 5
19- SDK Platform Android 4.0, API 14, revision 4
20- SDK Platform Android 3.2, API 13, revision 1
21- SDK Platform Android 3.1, API 12, revision 3
22- SDK Platform Android 3.0, API 11, revision 2
23- SDK Platform Android 2.3.3, API 10, revision 2
24- SDK Platform Android 2.3.1, API 9, revision 2
25- SDK Platform Android 2.2, API 8, revision 3
26- SDK Platform Android 2.1, API 7, revision 3
27- Google APIs, Android API 24, revision 1
28- Google APIs, Android API 23, revision 1
29- Google APIs, Android API 22, revision 1
30- Google APIs, Android API 21, revision 1
31- Google APIs, Android API 19, revision 20
32- Glass Development Kit Preview, Android API 19, revision 11
33- Google APIs, Android API 18, revision 4
34- Google APIs, Android API 17, revision 4
35- Google APIs, Android API 16, revision 4
36- Google APIs, Android API 15, revision 3
37- Android Support Repository, revision 47
38- Android Auto Desktop Head Unit emulator, revision 1.1
39- Google Play services, revision 49
40- Instant Apps Development SDK, revision 1.3
41- Google Repository, revision 58
42- Google Play APK Expansion library, revision 1
43- Google Play Licensing Library, revision 1
44- Android Auto API Simulators, revision 1
45- Google Web Driver, revision 2
然后安装指定更新
[root@mosee-pc build-scripts]# android update sdk -u -t 1,2,3,9,10,11

安装依赖库glibc 2.18

cd /opt
curl http://ftp.gnu.org/gnu/libc/glibc-2.18.tar.gz –output glibc-2.18.tar.gz
tar zxvf glibc-2.18.tar.gz
必须单独建立另一个目录
mkdir glibc-2.18-build
cd glibc-2.18-build
../glibc-2.18/configure –prefix=/usr –disable-profile –enable-add-ons –with-headers=/usr/include –with-binutils=/usr/bin
make
make install

下载SDL2

cd /usr/src/
wget https://libsdl.org/release/SDL2-2.0.5.tar.gz
wget https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.tar.gz
wget https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.tar.gz
wget https://www.libsdl.org/projects/SDL_net/release/SDL2_net-2.0.1.tar.gz
wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz

tar xf SDL2-2.0.5.tar.gz
tar xf SDL2_image-2.0.1.tar.gz
tar xf SDL2_mixer-2.0.1.tar.gz
tar xf SDL2_net-2.0.1.tar.gz
tar xf SDL2_ttf-2.0.14.tar.gz

ln -s SDL2-2.0.5 SDL2
ln -s SDL2_image-2.0.1 SDL2_image
ln -s SDL2_mixer-2.0.1 SDL2_mixer
ln -s SDL2_net-2.0.1 SDL2_net
ln -s SDL2_ttf-2.0.14 SDL2_ttf

cd /usr/src/SDL2/
cd build-scripts/
./androidbuild.sh org.libsdl /dev/null
cd ../build/org.libsdl/

rm -rf jni/src/

ln -s /usr/src/SDL2_image jni/
ln -s /usr/src/SDL2_image/external/libwebp-0.3.0 jni/webp
ln -s /usr/src/SDL2_mixer jni/
ln -s /usr/src/SDL2_mixer/external/libmikmod-3.1.12 jni/libmikmod
ln -s /usr/src/SDL2_mixer/external/smpeg2-2.0.0 jni/smpeg2
ln -s /usr/src/SDL2_net jni/
ln -s /usr/src/SDL2_ttf jni/

设置环境变量

cd ~
vim .bash_profile
#增加如下环境变量
PATH=”/opt/android-ndk-r17: PATH”                                  # for ‘ndk-build’  PATH=”/opt/android-sdk-linux/tools: PATH” # for ‘android’
PATH=”/opt/android-sdk-linux/platform-tools:$PATH” # for ‘adb’

编译SDL2

cd /usr/src/SDL2
cd build-scripts
vim androidbuild.sh
找到ANDROID update project行,增加–target android-XX,其中android-XX可以通过android list targets查看当前有哪些?
[root@mosee-pc build-scripts]# android list targets

Available Android targets:

id: 1 or “android-22”
Name: Android 5.1.1
Type: Platform
API level: 22
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in

Tag/ABIs : no ABIs.

id: 2 or “android-23”
Name: Android 6.0
Type: Platform
API level: 23
Revision: 3
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in

Tag/ABIs : no ABIs.

id: 3 or “android-24”
Name: Android 7.0
Type: Platform
API level: 24
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : no ABIs.

&ANDROID update project –target android-24 –path
&BUILDPATHz

修改APP_ABI和APP_PLATFORM,如果APP_ABI包含x86,在编译SDL_image会报错误
/usr/src/SDL2-2.0.5/build/org.libsdl/jni/SDL2_image/external/jpeg-9/jidctfst.S:17:10: fatal error: ‘machine/cpu-features.h’ file not found

vim jni/Application.mk
APP_ABI := armeabi-v7a
APP_PLATFORM=android-14

进入build/org.libsdl执行编译
[root@mosee-pc org.libsdl]# ndk-build -aj在$(nprzoc)

编译后在obj/local/armeabi-v7a目录下生成共享文件libSDL2.so

猜你喜欢

转载自blog.csdn.net/MoSee/article/details/81328653