搭建SDL 的Android 开发环境,的详细步骤(建立sdl2.0 for Android开发环境)
1.安装下载jdk,进入该网页: http://java.sun.com/javase/downloads/index.jsp (或者直接点击下载)如下图:
选择 Download JDK 只下载JDK,无需下载jre.
我这里是用的windows xp,32位机器,所以下载 windows X86 i586,下面我都是以windows xp为基础来说明。
我这里下载了两个,你要下载最新版的,并且安装最新版的就可以了。
2.下载安装,Android SDK,地址:
http://developer.android.com/sdk/index.html
选自己的对应机型下载。
点击如上图,下载,下载完毕(我这里是32位的xp)
3.下载android-ndk-r7b安装包,下载地址:
地址:http://developer.android.com/sdk/ndk/index.html
下载后解压缩到你的工作目录,例如:C:\Android\android-ndk-r9c,结果如下图:
现在你下载好最新的ndk并且解压出来了:
Android ndk包含build、docs、samples、sources、GNUmakefile、ndk-build、ndk-gdb及readme等内容。
其中samples下面包含几个实例开发演示项目。
4.注意,网上有些人说要另外下载Eclipse,现在其实是不需要的,只需要下载Android SDK,里面集成了相对于Android开发的Eclipse。
5.下载完毕,先安装JDK, 安装jdk如图:
然后安装Android SDK,只需解压下载的压缩包,注意不要有中文路径,很多开发工具不支持中文。
解压完之后,如图:
adt-bundle-windows-x86-20131030就是sdk以及Eclipse开发工具,google人性化很好,非常绿色(就是我的老爷机用起来很慢)。
6. 最后解压安装ndk。只要将ndk解压到你的想要的文件目录下面便可(强调:解压出来的路径不要有中文),我的如下图:
7. 打开adt-bundle-windows-x86-20131030 文件夹里面的,Eclipse.exe,启动画面如图,这个就是Android的开发ide了:
8.在Eclipse中设定ndk。
指定你解压出来的ndk的文件路径:
9.到这里,你的Android ndk 开发环境以及算基本搭建完毕,可以试试建立一个 HelloWorld。
建立一个Android application :
设定 程序图标:
选择blank activity
看到Eclipse IDE 窗口左侧生成了一个helloworld的 activitiy
此时,创建了一个简单的Android空白工程,里面有HelloWorld语句;
10.创建一个Android模拟器来进行模拟程序:
在上面设定有段的模拟器的 内存,加速,版本,还有屏幕大小等参数。名字随你起。
然后运行你上面的helloworld。
弹出Android模拟器,开机启动Android中。。。。。
在这个时间,我的姥爷机特别慢......你如果也是老爷机,那么可以先去喝杯茶。
喝完茶之后,发现:
HelloWorld出现了。
//===========================================================================================//
11.你可以去搭建sdl图形开发环境了,现在的sdl2.0支持在Android用jni c去编程,不过据说SDL2.0 Android现在还有很多bug。
SDL(Simple DirectMedia Layer)是一套开放源代码的跨平台多媒体开发库,使用C语言写成。SDL提供了数种控制图像、声音、输出入的函数,让开发者只要用相同或是相似的代码就可以开发出跨多个平台(Linux、Windows、Mac OS X等)的应用软件。目前SDL多用于开发游戏、模拟器、媒体播放器等多媒体应用领域,而且现在支持Android(尽管不是很成熟)。
下面是在外国网上找到的我成功编译出来的教材,跟着他的步骤可以容易的配置Android SDL开发环境:
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
Android Programming using SDL and C - Setting up the Build System and Compiling a First Program
Sat, 07/28/2012 - 07:07 — Benjamin Caspari
As Android programs are usually written in Java, it's a bunch of work to set up the build system to write SDL programs in C. However, this will give you a better performance than writting them in Java, since the library itself is also written in C and JNI calls are expensive!
I have set up the build environment using Windows 7, but using Linux should work the same way.
1. Get the Android SDK and install it
Get the Android SDK from its official site and install it following the detailed instructions that you can find there, including Eclipse and the ADT plugin and setting up an Android virtual device. Make sure it works correctly, for example by compiling and starting the "Hello world" example.
2. Get the Android NDK and install it
Also download the Android NDK from here and extract it. I recommend adding the path to your PATH environment variable.
3. Get SDL 2.0
Download the source snapshot of SDL 2.0.
4. Create your project
After you extracted the source snapshot, copy the android-project directory and rename it. You will build your project directory based on this. Now, copy the SDL subdirectory from the archive into the jni directory of your project. Rename the SDL_config_android.h file in the includes subdirectory to SDL_config.h (Overwrite the existing one!). Place your SDL application source files into the jni\src directory and add all source files to the android.mk file there(其实SDL里面的文件就是官网下载的sdl加压出来的根目录的src和include,和Android.mk,注意要修个include里面的config头文件,替换掉原来的文件,同时候记得替换mk文件里面的YourSourceHere为你的源文件名):
Make sure that Android.mk in the SDL subdirectory contains "LOCAL_MODULE := SDL2" and not "LOCAL_MODULE := SDL" - this is a known bug in the source for now
Before compiling the C code, you should create an Eclipse project. Start Eclipse and choose "File -> New -> Other -> Android Project from Existing Code". Select your projets directory and create the corresponding clipse project. Select the right build target in the projects properties (at least Android 1.6!):
5. Compile and run your project
After saving your Eclipse project, open a command line, navigate to your projects base directory and call the ndk-build script from there. You should see a output similar like this:
If you get linker errors (e.g. missing OpenGL libs), be sure that the right target in your project.properties file is set (e.g. "target=android-10"). A quick and dirty soultion may be to add the line "APP_PLATFORM := android-9" to the file \build\core\add-application.mk.
Now you can run the project from Eclipse in your Android virtual device:
Now you can edit your programs properties and add new code - recompile the c code by calling the ndk-build script every time you changed it.
If you get lint errors complaining about the wrong Android API, go to the projects preferences, choose "Android Lint Preferences" and set the severity for NewApi to "Warning" or less - this is a known bug at the moment:
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
用上面“它” 的方法基本可以编译过去,我个人修改了些:
APP_STL:=gnustl_static
APP_ABI:=armeabi armeabi-v7a
同时我添加修个了自己的main.c的源代码:
然后,在工程文件的目录下面重新 ndk-build,可以生成SDL 库文件,编译通过,如图:
运行结果,刷红色的屏幕,跟程序一样,运行正常,ok,到这里停笔。
sdl Android 示例工程下载地址:
工程源码下载地址:
http://download.csdn.net/detail/mynameislinduan/6819481
如转载请标明出处,原创者Done Lin :http://my.csdn.net/mynameislinduan