您的位置:首页 > 其它

VR系列——Oculus Mobile SDK文档:二、移动SDK安装指南(三)

2017-11-06 21:33 495 查看

Android Studio基础

该指南针对在Android Studio和Gradle中使用Oculus Mobile SDK提供了一些建议,用以补充Android Studio相关文档。

将Eclipse项目迁移到Android Studio

关于如何将Eclipse项目导入到Android Studio的具体信息可以参考安卓的说明文档:http://developer.android.com/sdk/installing/migrate.html

从Oculus的原生样例开始:导入Gradle项目

安装完Android Studio后,首次运行时会显示欢迎界面,选择Import project,并打开Gradle项目的根目录。



为了方便起见,我们创建了Android Studio根项目,并涵盖所有的范例,从而能更快地学会使用SDK。你也可以导入MobileSDK VrSamples目录下的build.gradle文件,Android Studio无需导入所有范例即可自动添加所需的依赖关系。



Project Overview

建议将Project Overview默认的Android模式改为Project模式,这样一来整个目录结构会更清晰易读,导入的项目用粗体显示。



项目设置

项目导入完成后,打开菜单File > ProjectStructure…,确认SDK和NDK的路径配置正确,否则可能会构建失败。



配置、构建并运行目标程序

可能你会从Android Studio中直接在设备上构建并运行app,这里面包括一系列操作如:编译工程、构建AKP包、通过USB/Wi-Fi传入手机,已及准备好运行。

如果手机设置为开发者模式(详情请见“开发者模式”小节),app不需要连接Gear VR头显也可直接运行;若不在开发者模式下,运行时会提示你需连接移动设备和头显来启动app。

确保你已经依照Mobile SDK安装指南中的步骤进行配置,设备也已配置完成。app也必须使用Oculus签名文件(osig)进行签名(详情请见应用签名)

在构建项目前,可以在Android Studio工具栏中找到配置目标程序的下拉菜单,选择Edit Configurations…对目标程序进行配置。

一旦选择了左侧下拉菜单中的项目后就能看到旁边的Run和Debug图标。点击任意一个图标后就能构建并运行程序。



点击Run或Debug后,弹出Choose Device对话窗口,通常默认会设为模拟器。选择一个运行中的设备并选择恰当的设置项。

此外,不需要运行也可在Build菜单下对项目进行构建和清除操作。



同步项目

如果你要编辑一个*.gradle文件或安装Oculus Mobile SDK(包括Gradle Projects)的更新文件,你需要Gradle Sync来更新Android Studio项目文件。



如图所示,点击Android Studio工具栏中的Sync Project with Gradle Files。

Android Studio原生调试

本节主要介绍如何在Android Studio中进行原生语言app范例调试。

注意:Android Studio对原生语言的支持还不完善。一些开发人员反馈使用Lollipop (5.0.x)系统的Note 4和5.0.0系统的S6开发时曾遇到一些由调试事件引起的问题。如果你在使用调试功能的过程中遇到问题,可以试着更新软件系统,并在Oculus论坛知照我们。

导入项目时创建的默认配置只支持Java调试。

在Android Studio工具栏的配置下拉菜单中选择Edit Configurations…。



如下图创建新的Android Native配置项:



在Run/Debug Configuration对话窗口的General标签中输入该配置项的名称,选择目标模块,并选择目标设备模式:



在Run/Debug Configuration对话窗口的Native标签中添加符号路径:



请注意ndk构建的地方剥离了libs/目录里的库。你必须在obj/local/目录指出符号搜索路径。

这也不是一个递归搜索路径,所以你必须把完整的路径放到obj/local/armeabi-v7a目录下。



原生ndk-gdb调试

本指南提供了使用ndk-gdb 调试原生移动虚拟现实项目的基本建议,并打算补充相关的安卓Studio文档。

Android NDK包括一个功能强大的调试工具称为ndk-gdb,一个小的shell脚本封装的GDB。在命令行使用ndk-gdb增加了方便的功能到您的调试过程,通过允许例如添加断点,单步执行代码和检查变量。

创建断点

中断功能

(gdb) break SomeFunctionName()


或者

(gdb) break SomeClass::SomeMethod()


用法示例:

(gdb) break OVR::VrCubeWorld::Frame(OVR::VrFrame const&)
Breakpoint 2 at 0xf3f56118: file jni/../../../Src/VrCubeWorld_Framework.cpp, line 292.


注:GDB支持tab键自动完成符号名称。

中断文件:行

(gdb) break SomeFile.cpp:256


条件断点

添加 if 到您的中断命令的最后。

用法示例:

(gdb) break OVR::VrCubeWorld::Frame(OVR::VrFrame const&) if vrFrame.PredictedDisplayTimeInSeconds >
24250.0
Breakpoint 6 at 0xf3f58118: file jni/../../../Src/VrCubeWorld_Framework.cpp, line 292.


中断当前执行

当一个应用程序正在运行,按Control-C立即中断把GDB提示调出来。

分步

单步执行

(gdb) next


或者

(gdb) n


单步跟踪

(gdb) step


或者

(gdb) s


继续执行

(gdb) continue


或者

(gdb) c


打印

打印结构

你可以使用漂亮的印刷模式在结构元素之间添加新行(可选):

(gdb) set print pretty on


打印结构:

(gdb) print SomeStructVariable


用法示例:

(gdb) print currentRotation
$1 = {
x = 23185.9961,
y = 23185.9961,
z = 0,
static ZERO = {
x = 0,
y = 0,
z = 0,
static ZERO = <same as static member of an already seen type>
}
}


printf

用法示例:

(gdb) printf "x = %f\n", currentRotation.x
x = 23185.996094


断点命令

GDB断点可以设置为在被击中时自动执行任意命令。此功能可用于插入打印语句到你的代码而不需要重新编译或者甚至在程序中的关键点修改数据而不需要完全停止执行。它是用commands命令控制的。

您可以用一个可选的参数指定断点号,如果省略,则最后的断点被使用。然后你将看到一系列以>开始的行,在你输入gdb命令处(一个命令一行),这些命令将在断点被击中时执行,直到以end终止命令序列。

在下面的示例中,我们创建一个断点,在被击中后自动打印一个局部变量的值,然后继续执行:

(gdb) break OVR::VrCubeWorld::Frame(OVR::VrFrame const&)
Breakpoint 1 at 0xf3f56118: file jni/../../../Src/VrCubeWorld_Framework.cpp, line 292.
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>silent
>printf "time = %f\n", vrFrame.PredictedDisplayTimeInSeconds
>continue
>end


文本用户界面(TUI)

启用或禁用TUI,按Ctrl + X后按Ctrl + A.

有关TUI键盘快捷键的更多信息,见https://sourceware.org/gdb/onlinedocs/gdb/TUIKeys.html

原文如下

Android Studio Basics

This guide provides basic recommendations for working with the Oculus Mobile SDK in Android Studio and Gradle, and is intended to supplement the relevant Android Studio documentation.

Migrating Eclipse Projects to Android Studio

For a general discussion of how to import existing Eclipse projects into Android Studio, please see the instructions provided by Android here: http://developer.android.com/sdk/installing/migrate.html

Getting Started with Oculus Native Samples: Import Gradle Project

When you first launch Android Studio after initial setup, you will be presented with a Welcome screen. Select Import project and point it at our root Gradle project.



For convenience we have set up the root Android Studio project to include all of our samples which provides for a quick way to get started with our SDK. You may also import any build.gradle project in any of the Mobile SDK VrSamples directories, and Android Studio will automatically import the required dependencies without bringing in all of the samples.



Project Overview

We recommend changing the Project Overview from the default Android to Project, which provides a good overview of the entire directory structure, with imported project directories shown in bold.



Project Settings

After importing your project, verify that the SDK and NDK locations are configured properly in File > Project Structure…, or your build will fail.



Select Target Configuration, Build, and Run

You may build and run your application on your device directly from Android Studio. This will compile your project, build the APK, copy it to the phone via USB/Wi-Fi, and prepare it for launching.

If your phone is set to Developer Mode (see Developer Mode for instructions), your application will play without being inserted into your Gear VR headset. Otherwise, when the process completes you will be prompted to insert your mobile device into the headset to launch the application.

Make sure you have followed the configuration steps in the Mobile SDK Setup Guide to ensure your device is configured appropriately. Applications must be signed with an Oculus Signature File (osig) in order to run (see Application Signing for more information).

Select the target configuration you wish to build before building by selecting Edit Configurations… in the project dropdown menu in the Android Studio toolbar.

Immediately to the left of the project dropdown, you will see Run and Debug icons. Click on either icon to build and run your project.



After clicking on Run or Debug, the Choose Device dialog window will open. This is usually set to an emulator by default. Select Choose a running device and select the appropriate option.

You may also build and clean your project without running it by using the Build menu.



Syncing Projects

If you edit a *.gradle file or install an update to the Oculus Mobile SDK which includes updated Gradle Projects,



Click on Sync Project with Gradle Files in the Android Studio toolbar as shown.

Native Debugging with Android Studio

This sectio
bebd
n introduces debugging our sample native apps in Android Studio.

Note: Native support in Android Studio is still under development. Some developers have reported problems using run-as with the Note 4 with Lollipop (5.0.x) and S6 with 5.0.0, which may cause issues with debugging. If you have problems debugging, try updating to the latest system software, and please let us know on the Oculus Forums.

The default configurations created during project import only support Java debugging.

Select Edit Configurations… in the Configurations drop-down menu in the Android Studio toolbar.



Create a new Android Native configuration as show below:



In the General tab of the Run/Debug Configuration dialog box, assign your configuration a name, select the target module, and select the target device mode:



In the Native tab of the Run/Debug Configuration dialog box, add symbol paths:



Note that ndk-build places stripped libraries inside the libs/ directory. You must point the symbol search paths at the obj/local/ directory. This is also not a recursive search path, so you must put the full path to the obj/local/armeabi-v7a directory.。



Native Debugging with ndk-gdb

This guide provides basic recommendations for using ndk-gdb to debug native mobile VR projects, and is intended to supplement the relevant Android Studio documentation.

The Android NDK includes a powerful debugging tool called ndk-gdb, a small shell script wrapped around GDB. Using ndk-gdb from the command line adds convenient features to your debugging workflow by allowing, for example, adding breakpoints, stepping through code, and inspecting variables.

Create Breakpoints

Break On Function

(gdb) break SomeFunctionName()


or

(gdb) break SomeClass::SomeMethod()


Example usage:

(gdb) break OVR::VrCubeWorld::Frame(OVR::VrFrame const&)
Breakpoint 2 at 0xf3f56118: file jni/../../../Src/VrCubeWorld_Framework.cpp, line 292.


Note: GDB supports tab completion for symbol names.

Break On File:Line

(gdb) break SomeFile.cpp:256


Conditional Breakpoints

Add if to the end of your break command.

Example usage:

(gdb) break OVR::VrCubeWorld::Frame(OVR::VrFrame const&) if vrFrame.PredictedDisplayTimeInSeconds >
24250.0
Breakpoint 6 at 0xf3f58118: file jni/../../../Src/VrCubeWorld_Framework.cpp, line 292.


Break At Current Execution

Example usage:

(gdb) break OVR::VrCubeWorld::Frame(OVR::VrFrame const&) if vrFrame.PredictedDisplayTimeInSeconds >
24250.0
Breakpoint 6 at 0xf3f58118: file jni/../../../Src/VrCubeWorld_Framework.cpp, line 292.


Break At Current Execution

When an application is actively running, press control-c to break immediately and bring up the gdb prompt.

Stepping

Step Over

(gdb) next


or

(gdb) n


Step Into

(gdb) step


or

(gdb) s


Continue Execution

(gdb) continue


or

(gdb) c


Printing

Print Struct

You may enable pretty printing mode to add new lines between struct elements (optional):

(gdb) set print pretty on


To print the struct:

(gdb) print SomeStructVariable


Example usage:

(gdb) print currentRotation
$1 = {
x = 23185.9961,
y = 23185.9961,
z = 0,
static ZERO = {
x = 0,
y = 0,
z = 0,
static ZERO = <same as static member of an already seen type>
}
}


printf

Example usage:

(gdb) printf "x = %f\n", currentRotation.x
x = 23185.996094


Breakpoint Commands

GDB breakpoints may be set to automatically execute arbitrary commands upon being hit. This feature is useful for inserting print statements into your code without recompiling or even modifying data at key points in your program without halting execution entirely. It is controlled by the commands command.

You may specify the breakpoint number with an optional single argument; if omitted, the final breakpoint is used. You are then presented with a series of lines beginning with > where you may enter GDB commands (one per line) that will be executed upon hitting the breakpoint, until the command sequence is terminated with end. Mobile | Mobile SDK Setup Guide | 27 In the following example, we create a breakpoint automatically prints the value of a local variable and then continues execution, upon being hit:

(gdb) break OVR::VrCubeWorld::Frame(OVR::VrFrame const&)
Breakpoint 1 at 0xf3f56118: file jni/../../../Src/VrCubeWorld_Framework.cpp, line 292.
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>silent
>printf "time = %f\n", vrFrame.PredictedDisplayTimeInSeconds
>continue
>end


Text User Interface (TUI)

To enable or disable the TUI, press CTRL+x followed by CTRL+a.

For more information on TUI keyboard shortcuts, see https://sourceware.org/gdb/onlinedocs/gdb/TUIKeys.html.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐