SDL2 linux开发环境搭建记录,2016.09.28搭建成功,编译通过,sdl2 ubunt开发环境搭建记录:
ubunt编译SDL2.0.4详细教程,ubuntu编译SDL2详细过程:
ubuntu 16.04 x64虚拟机安装SDL2.0.4的工作记录,ubuntu搭建SDL2开发环境的过程记录:
设置环境变量,开发 android要切换到root用户:
下载目前SDL官网最新的开发包SDL源码包(https://www.libsdl.org/download-2.0.php):
下载之后,强烈建议先浏览一遍官方的SDL adroid编译教程wiki:
https://wiki.libsdl.org/Android
在linux ubuntu 16.04 x64下,首先切换超级用户,shell命令:
su
这样经过测试,编译可以通过,同时避免一些权限问题;
根据SDL官方文档,编译android SDL2 wiki,需要安装必要的工具:“JDK 和 ant”:
root@ubuntu:/home/linduan/Downloads/SDL2-2.0.4/build-scripts# sudo apt-get install openjdk-7-jdk ant
其中提示openjdk-7-jdk过期,替换的安装办法是:
root@ubuntu:/home/linduan/Downloads/SDL2-2.0.4/build-scripts# sudo apt-get install oracle-java7-installer
注意!后来编译的过程发现编译sdl android出错,不能通过,后面有解决办法;
下载NDK和android SDK(或者用Android Studio的SDK manager去下载 SDK):
2014.7版本
ADT Bundle
http://dl.google.com/android/adt/adt-bundle-windows-x86-20140702.zip
http://dl.google.com/android/adt/adt-bundle-windows-x86_64-20140702.zip
http://dl.google.com/android/adt/adt-bundle-mac-x86_64-20140702.zip
http://dl.google.com/android/adt/adt-bundle-linux-x86-20140702.zip
http://dl.google.com/android/adt/adt-bundle-linux-x86_64-20140702.zip
SDK Tools Only
http://dl.google.com/android/android-sdk_r23.0.2-windows.zip
http://dl.google.com/android/installer_r23.0.2-windows.exe
http://dl.google.com/android/android-sdk_r23.0.2-macosx.zip
http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz
Android Studio
http://dl.google.com/android/studio/install/0.8.6/android-studio-bundle-135.1339820-windows.exe
http://dl.google.com/android/studio/install/0.8.6/android-studio-bundle-135.1339820-mac.dmg
http://dl.google.com/android/studio/install/0.8.6/android-studio-bundle-135.1339820-linux.tgz
Android NDK
http://dl.google.com/android/ndk/android-ndk32-r10-windows-x86.zip
http://dl.google.com/android/ndk/android-ndk32-r10-windows-x86_64.zip
http://dl.google.com/android/ndk/android-ndk32-r10-darwin-x86.tar.bz2
http://dl.google.com/android/ndk/android-ndk32-r10-darwin-x86_64.tar.bz2
http://dl.google.com/android/ndk/android-ndk32-r10-linux-x86.tar.bz2
http://dl.google.com/android/ndk/android-ndk32-r10-linux-x86_64.tar.bz2
http://dl.google.com/android/ndk/android-ndk64-r10-windows-x86.zip
http://dl.google.com/android/ndk/android-ndk64-r10-windows-x86_64.zip
http://dl.google.com/android/ndk/android-ndk64-r10-darwin-x86.tar.bz2
http://dl.google.com/android/ndk/android-ndk64-r10-darwin-x86_64.tar.bz2
http://dl.google.com/android/ndk/android-ndk64-r10-linux-x86.tar.bz2
http://dl.google.com/android/ndk/android-ndk64-r10-linux-x86_64.tar.bz2
http://dl.google.com/android/ndk/android-ndk-r10-cxx-stl-libs-with-debug-info.zip
我用的是最新2016.09.20的NDK和 android studio 2.2 编译SDL, 先安装好Android 2.2,然后在android SDK manager下载 API level 12, 以及最新的level SDK,由于SDL2.04作者是通过API Level 12来编译SDL2的,这里最好也下载12,以免不兼容而报错;
设置全面的环境变量PATH,使得编译器能找到ndk,sdk,这里是我的环境变量,贴出给大家参考,根据个人的环境去修改:
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root/Android/Sdk/ndk-bundle:/root/Android:/root/Android/Sdk:/root/Android:/root/Android/Sdk:/root/Android/Sdk/tools:/root/Android/Sdk/platforms/android-15:/root/Android/Sdk/platform-tools:/root/Android/Sdk/platforms:/root/Android/Sdk/tools/proguard"
设置各个环境变量,这里是SDL官方网站的SDL环境变量,请根据自己的Andriod SDK和Android NDK路径去设定:
PATH="/usr/src/android-ndk-r8c:$PATH" # for 'ndk-build'
PATH="/usr/src/android-sdk-linux/tools:$PATH" # for 'android'
PATH="/usr/src/android-sdk-linux/platform-tools:$PATH" # for 'adb'
ANDROID_HOME="/root/Android/Sdk"////一定要这样写,不能用两个路径,否则找不到文件,报错:
/home/linduan/Downloads/SDL2-2.0.4/build/org.libsdl.testgles/build.xml:91: Cannot find /root/Android/Sdk:/root/Android/tools/ant/build.xml imported from /home/linduan/Downloads/SDL2-2.0.4/build/org.libsdl.testgles/build.xml
原因就是ANDROID_HOME不能有两个路径,只能有一个准确的路径;
上面设置好之后,就可以开发编译啦!编译命令和编译方法sdl wiki有写:
进入/home/linduan/Downloads/SDL2-2.0.4/build-scripts
shell运行官方编译脚本,脚本格式:./androidbuild.sh 生成apk名字 编译的c源文件:
./androidbuild.sh org.libsdl.testgles ../test/testgles.c
最后,提示:
BUILD SUCCESSFUL
Total time: 33 seconds
Your APK is ready at /home/xrz/Downloads/SDL2-2.0.4/build/org.libsdl.testgles/bin/org.libsdl.testgles-debug.apk
To install to your device:
cd /home/xrz/Downloads/SDL2-2.0.4/build/org.libsdl.testgles
ant debug install
表示SDL2编译成功,生成了apk,可以放到手机上去跑了。
报错以及处理:
过程出现是问题是环境变量没有设对,这个好解决,还有一个问题我头痛好久:
[dx] Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
[dx]at java.lang.ClassLoader.defineClass1(Native Method)
[dx]at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
[dx]at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[dx]at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[dx]at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
[dx]at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[dx]at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[dx]at java.security.AccessController.doPrivileged(Native Method)
[dx]at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[dx]at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[dx]at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[dx]at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[dx]at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
BUILD FAILED
/root/Android/Sdk/tools/ant/build.xml:888: The following error occurred while executing this line:
/root/Android/Sdk/tools/ant/build.xml:890: The following error occurred while executing this line:
/root/Android/Sdk/tools/ant/build.xml:902: The following error occurred while executing this line:
/root/Android/Sdk/tools/ant/build.xml:283: null returned: 1
后来经过搜索,大概了解原因,build.xml:283: null returned: 1不能直接修改xml,也不能像网上一些blog说的ant clean解决,其实问题的源头在Unsupported major.minor version 52.0错误,就是JDK版本不对,可能是JDK和android sdk,android ndk的版本不匹配,目前我用的是jdk7,那么去下载啦jdk8,同时设定默认的java指向最新的java版本8,这样可以编译通过啦:
Installing default JRE/JDK
sudo apt-get update
sudo apt-get install default-jre
sudo apt-get install default-jdk
Installing Oracle JDK
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Oracle JDK 6(旧版本)
sudo apt-get install oracle-java6-installer
Oracle JDK 7(较新的稳定版本)
sudo apt-get install oracle-java7-installer
Oracle JDK 8(最新预览版本)
sudo apt-get install oracle-java8-installer
更改系统默认java版本:
sudo update-alternatives –config java 有 2 个候选项可用于替换 java (提供 /usr/bin/java)。