osg for android学习之二:编译运行osgAndroidExampleGLES1/2

首先参考前一篇编译GLES1 GLES2的版本,注意不要用ndk-r8b的版本。
我的步骤如下:
打开eclipse,新建项目-android-从已有代码创建;
选择 F:\osgeo4w\osg\trunk\OpenSceneGraph\examples\osgAndroidExampleGLES2 ,勾选拷贝到工作空间
然后在eclipse中修改 jni/ Android.mk,
OSG_ANDROID_DIR := D:/osggles2 ##这个是你编译时的安装路径,如果没有指定,那就是这个路径 D:\cygwin\usr\local 
LOCAL_LDLIBS    := -llog -lGLESv2 -lz -lgnustl_static
修改 jni/Application.mk
APP_PLATFORM  := android-8
运行cygwin,cd 到项目根目录,就是F:\Android\eclipse_workspace\osg.AndroidExample.osgViewer
执行如下命令:
$ANDROID_NDK/ndk-build
成功后界面如下:
osg for android学习之二:编译运行osgAndroidExampleGLES1/2_第1张图片
接下来回到eclipse中,先把项目改个名,不然会因为名称重复无法导入另一个例子
然后编译该项目。
编译的时候会提示一些错误,如下:
osg for android学习之二:编译运行osgAndroidExampleGLES1/2_第2张图片
注释掉 @Override 即可。
然后点run-AS Android application.
就可以在bin下看到apk文件了。
在模拟器上运行不了,需要拷贝到真机上跑。
osg for android学习之二:编译运行osgAndroidExampleGLES1/2_第3张图片
至于调试:
avd貌似不支持opengl es的调试,反正我用4.0没调试成功。
先把手机开启usb调试模式,然后直接把手机连接电脑,注意不要开启u盘,电脑会自动安装手机的驱动,如果没有自动安装,自己去找驱动来装。
连接好后,在eclipse中直接点调试,默认就是手机了。


以下是参考:
After this is finished, we are ready to start the eclipse project. Before starting eclipse, copy the folder osgAndroidExampleGLES1 from
/home/USER/Android/OpenSceneGraph-3.0.1/examples
to
/home/USER/workspace/osgAndroidExampleGLES1
(or wherever else your eclipse workspace is).

Start eclipse and go to New → Project and choose “Android Project“. Next, then choose „Create project from existing source“ and set the location to
/home/USER/workspace/osgAndroidExampleGLES1
The Project Name should be osgAndroidExampleGLES1. (SCREENSHOT6)
Next, the build target should be Android 2.2 or higher.

Expand the project and open the folder jni. Open the file Android.mk
Change line 7 to:
OSG_ANDROID_DIR := /usr/local
Change line 21 to:
LOCAL_DLIBS := -llog -lGLESv1_CM -ldl -lz -lgnustl_static
and save it. (SCREENSHOT7)

In a Terminal window, go to the project directory
cd /home/USER/workspace/osgAndroidExampleGLES1
We need to update the build.xml. Type
$ANDROID_SDK/tools/android list targets
and look for „android-8“ (Name: Android 2.2) in the output. Remember the id. My id is 1. The next command to execute in the terminal is:
$ANDROID_SDK/tools/android update project -t 1 -p . -s
where you have to exchange the „1“ with your id number. After that, build the project by executing
$ANDROID_NDK/ndk-build

Now that we built the native part of the Android OSG Viewer, go back to eclipse and run it. That's it.


你可能感兴趣的:(eclipse,android,command,Build,Exchange,Terminal)