osg for android安装文档.docx

上传人:b****2 文档编号:23503257 上传时间:2023-05-17 格式:DOCX 页数:15 大小:530.65KB
下载 相关 举报
osg for android安装文档.docx_第1页
第1页 / 共15页
osg for android安装文档.docx_第2页
第2页 / 共15页
osg for android安装文档.docx_第3页
第3页 / 共15页
osg for android安装文档.docx_第4页
第4页 / 共15页
osg for android安装文档.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

osg for android安装文档.docx

《osg for android安装文档.docx》由会员分享,可在线阅读,更多相关《osg for android安装文档.docx(15页珍藏版)》请在冰豆网上搜索。

osg for android安装文档.docx

osgforandroid安装文档

OSGforandroid学习材料

Windows下编译安装

并且参考

http:

//lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2012-March/057074.html

1.前提

我的系统是windows7x64位英文版本(win2008英文版也编译通过)

osg是最新版,应该是3.0.2

记得不要用windows下的cmake,要用cygwin中的cmake命令。

记得一定要把系统环境变量Path加上D:

\cygwin\bin;F:

\Android\IDE\android-ndk-r8-windows,否则出现ANDROID_NDK NOTFOUND类似的错误(经过多次测试,不是环境变量的问题,是因为ndk-r8b会使用ANDROID_NDK作为NDK的调用命令,因此在cygwin配置文件修改的时候吧NDK改为ANDROID_NDK就可以了,android-ndk-r8b-windows是没有问题的)。

虽然用rb8,可以编译通过,但是在ndk-build的时候会报 themanglingof'va_list'haschangedinGCC4.4 的提示和错误,所以千万不要用r8b,我用r8,没有问题。

2. 准备

新建一个文件夹,如F:

\osgeo4w\osg\trunk

(1)安装TortoiseSVN-x64,在天空软件下的

在F:

/osgeo4w/osg/trunk目录下右键选择TortoiseSVN的checkout,输入http:

//www.openscenegraph.org/svn/osg/OpenSceneGraph/trunk

下载最新的osg,放在F:

/osgeo4w/osg/trunk/OpenSceneGraph下

(2)下载安装cygwin,并且把del的部分装完,这个过程需要花费2-3个小时,主要是下载时间。

(3)下载 3rdpartyAndroid.zip,注意不要用windows下的第三方库

下载链接在http:

//www2.ai2.upv.es/difusion/osgAndroid/3rdpartyAndroid.zip有89127k

(4)下载NDK,我下的是android-ndk-r8-windows.zip有107M,解压到某个目录下,如F:

\Android\IDE\android-ndk-r8-windows。

(5)打开cygwin安装目录下的.bash_profile文件,我的在D:

\cygwin\home\xuhy\.bash_profile,xuhy是你电脑的登录用户名。

在末尾加上NDK=/cygdrive/F/Android/IDE/android-ndk-r8-windowsexportNDK

如果使用 android-ndk-r8b-windows需要设置如下:

ANDROID_NDK=/cygdrive/F/Android/IDE/android-ndk-r8bexportANDROID_NDK

ANDROID_SDK=/cygdrive/F/Android/IDE/android-sdk_r20-windowsexportANDROID_SDK

然后运行D:

\cygwin\Cygwin.bat文件。

之后测试一下cygwin和NDK是否成功,方法如下:

③ 验证

重启cygwin,输入:

cd$NDK

能进入到ndk对应目录说明设置OK。

5 编译工程生成.so文件

2 必须以管理员权限运行,否则会出错,进入android项目工作目录:

cd$NDK

② 依次进入samples\hello-jni目录,完整路径为F:

\Android\IDE\android-ndk-r8-windows\samples\hello-jni

③ 运行:

$NDK/ndk-build。

注意:

该命令$NDK和/ndk-build是连接到一起的,中间没有空格,实际使用时输入完整命令$NDK/ndk-build,不能只输入ndk-build

正常编译编译后,当前目录下生成两个文件夹libs和obj,在项目libs/armeabi目录下生成对应的.so文件。

3.开始

把3rdpartyAndroid.zip解压到F:

/osgeo4w/osg/trunk/OpenSceneGraph下,如下,cmake的时候会自动去搜索。

然后在F:

/osgeo4w/osg/trunk/OpenSceneGraph中新建一个文件夹为build之后,管理员权限运行cygwin,cd到这个build目录下,输入如下命令:

如果是编译GLES1版本,输入如下:

cmake..-DOSG_BUILD_PLATFORM_ANDROID=ON-DDYNAMIC_OPENTHREADS=OFF-DDYNAMIC_OPENSCENEGRAPH=OFF-DOSG_GL_DISPLAYLISTS_AVAILABLE=OFF-DOSG_GL_MATRICES_AVAILABLE=ON-DOSG_GL_VERTEX_FUNCS_AVAILABLE=ON-DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE=ON-DOSG_GL_FIXED_FUNCTION_AVAILABLE=ON-DOSG_CPP_EXCEPTIONS_AVAILABLE=OFF-DOSG_GL1_AVAILABLE=OFF-DOSG_GL2_AVAILABLE=OFF-DOSG_GL3_AVAILABLE=OFF-DOSG_GLES1_AVAILABLE=ON-DOSG_GLES2_AVAILABLE=OFF-DJ=4

如果编译GLES2版本,输入如下:

cmake..-DOSG_BUILD_PLATFORM_ANDROID=ON-DDYNAMIC_OPENTHREADS=OFF-DDYNAMIC_OPENSCENEGRAPH=OFF-DOSG_GL_DISPLAYLISTS_AVAILABLE=OFF-DOSG_GL_MATRICES_AVAILABLE=OFF-DOSG_GL_VERTEX_FUNCS_AVAILABLE=OFF-DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE=OFF-DOSG_GL_FIXED_FUNCTION_AVAILABLE=OFF-DOSG_CPP_EXCEPTIONS_AVAILABLE=OFF-DOSG_GL1_AVAILABLE=OFF-DOSG_GL2_AVAILABLE=OFF-DOSG_GL3_AVAILABLE=OFF-DOSG_GLES1_AVAILABLE=OFF-DOSG_GLES2_AVAILABLE=ON-DJ=4

<在win2008下又编译了一次,GLES2版本,在后面加上了-DANDROID_PLATFORM=8-DANDROID_STL="gnustl_static"-DCMAKE_INSTALL_PREFIX=/cygdrive/d/osggles2,编译和安装都没有问题

安装后结果如下

>

其他参数还有

-DANDROID_NDK={PathtoyourNDKrootdirectory}

-DANDROID_ABI"armeabiarmeabi-v7a"

-DANDROID_PLATFORM=8

-DANDROID_STL="gnustl_static"

-DANDROID_DEBUG

-DANDROID_OPTIM_NEON

-DANDROID_OPTIM_ARM32

-DJ=4

-DCMAKE_INSTALL_PREFIX=/cygdrive/d/osggles2

我没有用到。

然后回车。

控制台会输出很多信息,包括他找到第三方库和NDK的信息。

之后make,会等很久,大概2个小时以上。

成功后界面如下:

然后makeinstall,一分钟以内,界面如下:

从图上可以看到,安装的位置在usr/local......下面,也就是说是在cygwin模拟的linux环境下的。

至此,据说可以运行例子了,怎么运行?

我还没试。

注意看安装目录obj\local\ 下的有没有如下.a文件,如果没有,从第三方库拷贝过来,否则链接的时候会报错。

编译运行osgAndroidExampleGLES1/2

首先参考前一篇编译GLES1GLES2的版本,注意不要用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

成功后界面如下:

接下来回到eclipse中,先把项目改个名,不然会因为名称重复无法导入另一个例子

然后编译该项目。

编译的时候会提示一些错误,如下:

注释掉@Override即可。

然后点run-ASAndroidapplication.

就可以在bin下看到apk文件了。

在模拟器上运行不了,需要拷贝到真机上跑。

至于调试:

Øavd貌似不支持opengles的调试,反正我用4.0没调试成功。

Ø先把手机开启usb调试模式,然后直接把手机连接电脑,注意不要开启u盘,电脑会自动安装手机的驱动,如果没有自动安装,自己去找驱动来装。

Ø连接好后,在eclipse中直接点调试,默认就是手机了。

以下是参考:

Afterthisisfinished,wearereadytostarttheeclipseproject.Beforestartingeclipse,copythefolderosgAndroidExampleGLES1from/home/USER/Android/OpenSceneGraph-3.0.1/examplesto/home/USER/workspace/osgAndroidExampleGLES1(orwhereverelseyoureclipseworkspaceis).

StarteclipseandgotoNew→Projectandchoose“AndroidProject“.Next,thenchoose„Createprojectfromexistingsource“andsetthelocationto/home/USER/workspace/osgAndroidExampleGLES1

TheProjectNameshouldbeosgAndroidExampleGLES1.(SCREENSHOT6)Next,thebuildtargetshouldbeAndroid2.2orhigher.

Expandtheprojectandopenthefolderjni.OpenthefileAndroid.mkChangeline7to:

OSG_ANDROID_DIR:

=/usr/local

Changeline21to:

LOCAL_DLIBS:

=-llog-lGLESv1_CM-ldl-lz-lgnustl_static

andsaveit.(SCREENSHOT7)

InaTerminalwindow,gototheprojectdirectory

cd/home/USER/workspace/osgAndroidExampleGLES1

Weneedtoupdatethebuild.xml.Type

$ANDROID_SDK/tools/androidlisttargets

andlookfor„android-8“(Name:

Android2.2)intheoutput.Remembertheid.Myidis1.Thenextcommandtoexecuteintheterminalis:

$ANDROID_SDK/tools/androidupdateproject-t1-p.-s

whereyouhavetoexchangethe„1“withyouridnumber.Afterthat,buildtheprojectbyexecuting

$ANDROID_NDK/ndk-build

NowthatwebuiltthenativepartoftheAndroidOSGViewer,gobacktoeclipseandrunit.That'sit.

老外的步骤,包括编译和运行例子

Idecidedtowriteaveryeasystep-for-steptutorialonhowtobuildOSGforAndroid.I'mgoingtoshareithere.Correctionsareofcoursewelcome. 

ThisTutorialistoshowhowtocompileOpenSceneGraphforAndroidandhowtobuildtheExampleApplicationosgVieweronUbuntu11.10.Itismeantasadditionalhelpanddoesnotexemptthedeveloperfromreading 

http:

//www.openscenegraph.org/projects/osg/wiki/Support/PlatformSpecifics/Android <这个比较重要,建议看看>

and 

 

Screenshotsareavailablehere:

  

InitialrequirementsareanalreadyworkingAndroidDevelopmentEnvironment.IamusingEclipseIndigo,AndroidSDKr16,AndroidNDKr7b.Furtherrequiredarecmakeandg++. 

Inthistutorial $HOME alwaysstandsfor /home/USER where USER denotestheusername. 

InstallSynapticusingtheSoftwareCenter(SCREENSHOT1). 

Installthepackageopenjdk-6-jdkusingSynaptic(SCREENSHOT2). 

InstallthefollowingpackagesusingSynapticorapt-get. 

cmake(sudoapt-getinstallcmake) 

g++ 

DownloadEclipseandextractit.I'musing 

$HOME/Android/eclipse/ 

MyversionisEclipseIndigo. 

DownloadtheAndroidSDK(myversion:

r16)andextractitinto 

$HOME/Android/android-sdk-linux/ 

InstalltheADT-Pluginintoeclipse.Thisworkslikethis:

starteclipseandonthetoppanelgoto Help→InstallNewSoftware.IntheFieldlabeled„Workwith:

“fillin:

 

https:

//dl- 

andpressEnter(SCREENSHOT3).Afterithasloadedthesources(„DeveloperTools“isvisible)(screenshot),checkthe„DeveloperTools“andclickNextuntileverythingisinstalled. 

Afterrestartingeclipsegoto Window→AndroidSDKManager.InstallATLEASTAndroid2.2(API8).ThisistheminimumrequiredversionforOSGonAndroid.(SCREENSHOT4).Iinstalleditto 

$HOME/Android/android-sdks/ 

tohaveitallinoneplace. 

ExtracttheAndroidNDKto 

$HOME/Android/android-ndk-r7b/ 

Developerswithanalreadyworkingenvironmentshouldbeabletostarthere. 

InstallingOpenSceneGraph3.0.1forAndroidwithOpenGLES1.x 

DownloadOpenSceneGraph-3.0.1andextractitto 

$HOME/Android/OpenSceneGraph-3.0.1/ 

Downloadthe3rdPartyDependenciesandextractitto 

$HOME/Android/OpenSceneGraph-3.0.1/3rdparty/ 

SettheenvironmentvariableANDROID_NDKsothatthecmakebuildingscriptcanfindit.Goto 

/home/USER/ 

andopenthefile .bashrc.Youmightneedtomakeitvisible.DothiswithCTRL+H. 

Editthefile(addthefollowinglinestotheend):

 

exportANDROID_NDK=$HOME/Android/android-ndk-r7b 

exportANDROID_SDK=$HOME/Android/android-sdks 

(alternativelyyoucanuse /home/USER/ insteadof $HOME/)(SCREENSHOT5).IaddedavariablefortheSDKtoo,sothatwedon'talwayshavetotypethefullpathwhenaccessingtheSDKfolderfromthecommandline.Saveit. 

OpenaTerminal.Typethefollowingcommands(replaceUSERwithyourusername):

 

mkdir$HOME/Android/OpenSceneGraph-3.0.1/build 

mkdir$HOME/Android/OpenSceneGraph-3.0.1/osginstall 

cd$HOME/Android/OpenSceneGraph-3.0.1/build 

Thiscreatedadirectory build intheOpenSceneGraph-directory.Thisiswherewewillplaceourbuildin.The osginstall directoryiswherethemakeinstallcommandwilllaterinstallourlibrariesandheaderfilesin.Thenextcommandwillcreatethenecessarymakefiles.Changethelastparameteraccordingtothenumberofcpu-coresyouhave.Isetitto4,becauseIhaveaquadcore. 

cmake..-DOSG_BUILD_PLATFORM_ANDROID=ON-DDYNAMIC_OPENTHREADS=OFF-DDYNAMIC_OPENSCENEGRAPH=OFF-DOSG_GL_DISPLAYLISTS_AVAILABLE=OFF-DOSG_GL_MATRICES_AVAILABLE=ON-DOSG_GL_VERTEX_FUNCS_AVAILABLE=ON-DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE=ON-DOSG_GL_FIXED_FUNCTION_AVAILABLE=ON-DOSG_CPP_EXCEPTIONS_AVAILABLE=OFF-DOSG_GL1_AVAILABLE=OFF-DOSG_GL2_AVAILABLE=OFF-DOSG_GL3_AVAILABLE=OFF-DO

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 唐诗宋词

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1