Android Studio开发环境安装(测试版)
本节介绍了构建原生的Oculus公司的移动应用程序时,Android Studio IDE 和Gradle的安装配置。
Android已经弃用了对Eclipse、ADT和Ant的支持,现在指定 Android Studio和Gradle作为核心的开发工具。Oculus公司的移动SDK 1.0引入了与Android Studio和Gradle的测试集合,我们后续不会再发支持Eclipse项目文件作为我们的SDK 例子或 库文件。
Oculus公司对Android Studio 的支持还是处于测试阶段,因为IDE还正在开发中并且核心组件还未完成(例如:NDK集成目前还只支持预览)。我们保留我们在Eclipse中的说明,但是我们还是建议您可以开始计划将项目迁移到Android Studio或您更喜欢的IDE上,因为Android已经宣布他们打算终止对Eclipse的支持。我们建议刚开始开发的开发商直接开始使用Android Studio。
有关之前的安装迁移到Android Studio的信息,请参见章节“Migrating Eclipse Projects to Android Studio in Android Studio Setup and Basics”
如果你在安装或使用Studio时遇到问题,请写在我们的Oculus论坛上让我们知道。
Windows系统下的Android Studio开发软件的安装
为了开发Android应用程序,你必须在系统上安装一下软件:
- Java 开发工具包(JDK)
- Android Studio 开发套件或独立的Android SDK工具
- Android 原生开发套件(NDK)
建议安装Gradle,但不是必需的。查看“Gradle”获取更多信息。
Java开发工具包(JDK)
Java开发工具包是Android Studio 和Gradle的先决条件。
目前最新的测试版本是JDK 8u45,可以从Java归档下载页面进行获取:
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html
最新的JDK版本可以在这里找到:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下载并安装后,需要添加环境变量JAVA_HOME并将其值设置为JDK的安装位置。例如,如果你已经安装了X64的版本,值可能是:
C:\ Program Files\Java\jdk1.8.0_45。
基于Java SE 8u45的默认安装路径,当使用命令行进行设置时的正确语法如下:
set JAVA_HOME=”C:\Program Files\Java\jdk1.8.0_45”
注意:JAVA_HOME的值必须是你实际安装的路径,可能与这些示例不同。
另外,添加的JDK的路径到PATH的值中,例如:C:\Program Files\Java\jdk1.8.0_45\bin
Android Studio 的安装
从下面的地址下载Android Studio 开发套件:https://developer.android.com/sdk/index.html
Android Studio 开发套件包括了开始开发Java Android应用程序所需的基本工具:
- Android Studio IDE
- Android SDK 工具
- 最新的Android平台
- 最新模拟器的系统映像
下载完成后,请按照下面介绍的进行相关的安装:
https://developer.android.com/sdk/installing/index.html?pkg=studio
安装附加的软件包和工具
你必须通过Android Studio SDK 管理中心下载Moblie SDK所需的附加软件包,在菜单工具(Tool)AndroidSDKManager即可打开。当第一次启动AndroidStudio时,Android Studio可能会自动的提示你走到这一步。
下面是本地开发需要的软件包:
- Android SDK 4.42版本,API级别为19或更高版本
- Android Build Tools 22.01版本
在SDK 管理中心(SDK Manager)的SDK工具选项卡上,以下可选的软件包和移动SDK是一同工作的:
- Android SDK Tools 版本23.0.2
- Android SDK Platform-tools 版本20
- Android SDK Build-tools 版本20
有关更多的安装附加软件包的信息,请访问:
https://developer.android.com/sdk/installing/adding-packages.html
Android 原生开发套件(NDK)
Android 原生开发套件(NDK)是一个工具集,可以让你实现部分应用程序使用原生编程代码语言如C和C++。包括这边版本,它被广泛使用在示例应用程序上。
注意:你可以在安装Android Studio的过程中安装NDK,但是我们建议你手动安装它,确保命令行环境的配置与Android Studio的设置一致。
最新NDK和移动SDK共同工作的版本是r10e。
- 从以下网站上下载NDK相关版本
https://developer.android.com/ndk/downloads/index.html. - 保存exe文件到你想安装它的目录,例如:C:\Dev\Android\android-ndk-r10e\
- 下载完成后,双击exe解压到当前目录下
- 添加NDK的路径到PATH中,例如:C:\Dev\Android\android-ndk-r10e\
- 添加环境变量ANDROID_NDK,并将其值设置为NDK的安装目录。如:C:\Dev\Android\android-ndk-r10e
- 使用上述的路径作为一个例子,使用命令行配置环境变量正确的语法是:
set ANDROID_NDK=C:\Dev\Android\android-ndk-r10e
Gradle
Gradle是一个自动化构建集,使用我们独立的构建脚本,并通过Android Studio管理依赖关系,允许自定义生成逻辑。Gradle取代了以前的Android构建系统,现在Android开发已经弃用的Ant。
使用移动SDK不用必须安装Gradle。Oculus公司移动SDK 1.0+构建脚本使用Gradle Wrapper (gradlew),小包装,自动下载并安装Gradle在你第一次构建项目时。但是如果你想安装完整版的Gradle,我们也有说明。最新测试发布的版本是Gradle2.7.如果你要Gradle源文件和离线文档,可以选择完整版下载。
安装Gradle:
- 下载2.7版本:http://gradle.org/gradle-download/
- 解决到所需的开发目录,如:C:\Dev\Android\gradle-2.7.
- 添加Gradle bin目录到PATH环境变量,例如:C:\Dev\Android\gradle-2.7\bin
- 重启终端命令窗口,以便获取更新后的PATH变量
- 现在应该能够构建:build –g
Mac OS X系统下的Android Studio开发软件的安装
为了开发Android应用程序,你必须在系统上安装一下软件:
- XCode
- Java开发工具包(JDK)
- Android Studio
- Android 原生开发套件(NDK)
建议安装Gradle,但不是必需的。查看章节“Gradle”获取更多信息。
XCode
安装任何Android开发工具前,你必须安装XCode
一旦安装完成后,下面的一些步骤(如安装JDK)可能是不必要的。
要下载XCode,请访问:https://developer.apple.com/xcode/download/
Java开发工具包(JDK)
如果JDK不存在你的系统上,请安装JDK。但如果你已经安装了XCode,这一步可能不是必要的。
JDK最新的测试版本是JDK8u45。它可以在下面的地址进行下载:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html.
Android Studio
从下面的地址可以下载Android Studio:https://developer.android.com/sdk/index.html
Android Studio 开发套件包括了开始开发Java Android应用程序所需的基本工具:
- Android Studio IDE
- Android SDK 工具
- 最新的Android平台
- 最新模拟器的系统映像
下载完成后,请按照下面介绍的进行相关的安装:
https://developer.android.com/sdk/installing/index.html?pkg=studio
安装附加软件包和工具
你必须通过Android Studio SDK 管理中心下载Moblie SDK所需的附加软件包,在菜单工具(Tool)AndroidSDKManager即可打开。当第一次启动AndroidStudio时,Android Studio可能会自动提示你走到这一步。
原生开发环境中需导入以下几个包:
- Android SDK 4.42. API level 19 或更高版本
- Android Build Tools 22.0.1
在SDK Manager->SDK Tools标签下的可选包与Mobile SDK搭配使用:
- Android SDK Tools 23.0.2
- Android SDK Platform-tools 20
- Android SDK Build-tools 20
更多附加包相关信息请参考https://developer.android.com/sdk/installing/adding-packages.html
安卓原生开发工具集(NDK)
安卓原生开发工具集让开发人员能够使用像C或C++这样的原生语言进行安卓app开发。这在此次发布的app样例中得到广泛的应用。
此次发布的最新版本NDK r10e已经通过测试验收,可在此下载:https://developer.android.com/tools/sdk/ndk/index.html。
下载完成后,将NDK放在home/dev目录下(~/dev)。dev目录文件如下图:
确认Android Studio和NDK已经导入到各自的文件夹下。这些文件夹的命名可以根据喜好决定,但必须要分别在不同的文件夹下安装,避免两个包发生冲突。
更多关于NDK安装和使用的信息可以参考:http://developer.android.com/tools/sdk/ndk/index.html#installing。
Gradle
Gradle是一种自动化构建工具,它使用独立的构建脚本,通过Android Studio管理依赖关系,并允许用户定制构建逻辑。Gradle替代了之前的安卓构建系统Ant,后者目前已不推荐在安卓开发中使用。
使用Mobile SDK并不一定要安装Gradle。Oculus Mobile SDK 1.0以上版本可以用Gradle Wrapper (gradlew)来构建脚本,它是一种小型的封装工具,在你第一次构建项目时会自动下载并安装Gradle。但如果你想要安装完整版的Gradle,请参考下文。
此次发布的最新版本Gradle 2.7已经通过测试验收,若需要Gradle源码和脱机文档,选择完整版进行下载。
手动安装
- 从http://gradle.org/gradle-download/下载(版本需为2.5以上)
- 导入到常见的开发目录下,例如:~/android/gradle-2.7
- 在环境变量PATH中添加Gradle的bin目录,例如:~/android/gradle-2.7/bin
- 打开新的Terminal窗口,更新环境变量PATH。
现在你可以使用命令行./build.py -g来进行构建
使用Brew安装:
需准备好Brew和OS X系统的可选包管理工具。
- 在Terminal中运行sudo brew install gradle
- 打开新的Terminal窗口,更新环境变量PATH。
现在你可以使用命令行./build.py -g来进行构建
使用MacPorts安装:
需准备好MacPorts和OS X系统的可选包管理工具。
- 在Terminal中运行sudo port install gradle
- 打开新的Terminal窗口,更新环境变量PATH。
现在你可以使用命令行./build.py -g来进行构建
原文如下
Android Studio Development Environment Setup (Beta)
This section describes setup and configuration of the Android Studio IDE and Gradle for building native Oculus Android mobile applications.
Android has deprecated support for Eclipse, ADT, and Ant, and now specifies Android Studio and Gradle as its core development tools. Oculus Mobile SDK 1.0 introduces our beta integration with Android Studio and Gradle, and we no longer ship Eclipse project files for our SDK samples or libs.
Oculus support for Android Studio is in beta, as the IDE is under development and key components are not complete (e.g., NDK integration is currently offered with Preview Support only). We are retaining our legacy Eclipse instructions for now, but recommend that you begin planning migration to Android Studio or to your preferred IDE, as Android has announced their intention to terminate Eclipse support. For developers who are just beginning, we recommend starting with Android Studio.
For information on migrating to Android Studio from previous installations, see Migrating Eclipse Projects to Android Studio in Android Studio Setup and Basics.
If you have problems installing or using Studio, please let us know on the Oculus Forums.
Android Studio Development Software Setup for Windows
In order to develop Android applications, you must have the following software installed on your system:
- Java Development Kit (JDK)
- Android Studio Development Bundle or Standalone Android SDK Tools
- Android Native Development Kit (NDK)
Gradle installation is recommended but not required. See Gradle for more information.
Java Development Kit (JDK)
The Java Development Kit is a prerequisite for Android Studio and Gradle.
The latest version which has been tested with this release is JDK 8u45, available from the Java Archive Downloads page: http://www.oracle.com/technetwork/java/javase/downloads/java-archivejavase8-2177648.html
The latest JDK version is available here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Once downloaded and installed, add the environment variable JAVA_HOME and set its value to the JDK install location. For example, the value may be C:\Program Files\Java\jdk1.8.0_45, if you have installed the x64 version.
Based on the default installation path of Java SE 8u45, the correct syntax when using set from the command line is:
set JAVA_HOME=”C:\Program Files\Java\jdk1.8.0_45”
Note: The JAVA_HOME value must be your actual path, which may differ from these examples.
Additionally, add the JDK to the value of your PATH, e.g. C:\Program Files\Java\jdk1.8.0_45\bin
Android Studio Installation
Download the Android Studio Bundle from the following location: https://developer.android.com/sdk/index.html
The Android Studio Development Bundle includes the basic tools you need to begin developing Java Android Applications:
- Android Studio IDE
- Android SDK tools
- Latest Android Platform
- Latest System Image for Emulator
Once downloaded, follow Android’s installation instructions: https://developer.android.com/sdk/installing/index.html?pkg=studio
Installing Additional Packages and Tools
You must download additional packages required by the Mobile SDK via the Android Studio SDK Manager, found in Tools > Android > SDK Manager. Android Studio may prompt you to take this step automatically the first time you launch it.
The following packages are required for native development:
- Android SDK 4.42. API level 19 or later
- Android Build Tools 22.0.1
The following optional packages under the SDK Tools tab in the SDK Manager are known to work with the Mobile SDK:
- Android SDK Tools 23.0.2
- Android SDK Platform-tools 20
- Android SDK Build-tools 20
More information about installing additional packages is found here: https://developer.android.com/sdk/installing/adding-packages.html
Android Native Development Kit (NDK)
The Android Native Development Kit (NDK) is a toolset that allows you to implement parts of your app using native code languages such as C and C++. It is used extensively by the sample applications included with this release.
Note: You may install the NDK during the Android Studio installation process, but we recommend installing it manually to be sure that your command-line environment is set up properly and agrees with your Studio setup.
The last version of the NDK known to work with the Mobile SDK is r10e.
- Download the appropriate version of NDK from the following location: https://developer.android.com/ndk/downloads/index.html.
- Save the exe to the directory where you would like to install it, e.g., C:\Dev\Android\android-ndk-r10e.
- Once downloaded, double-click the exe to unpack its contents into the parent directory.
- Add the NDK location to your PATH. For example: C:\Dev\Android\android-ndk-r10e\
- Add the environment variable ANDROID_NDK, and set the value to your Android NDK location. For example: C:\Dev\Android\android-ndk-r10e
- Using the above location as an example, the correct syntax for setting your environment variable using set from the command line is: set ANDROID_NDK=C:\Dev\Android\android-ndk-r10e
Gradle
Gradle is a build automation suite used by our standalone build scripts and by Android Studio to manage dependencies and allow for custom build logic. Gradle replaces the previous Android build system, Ant, which is now deprecated for use in Android development.
It is not necessary to install Gradle to use the Mobile SDK. Oculus Mobile SDK 1.0+ build scripts use the Gradle Wrapper (gradlew), a small wrapper that automatically downloads and installs Gradle the first time you build a project. However, if you wish to install the full version of Gradle, we have included instructions.
The latest version which has been tested with this release is Gradle 2.7. Choose the Complete download if you want the Gradle source and offline documentation.
To install Gradle:
- Download version 2.7 from http://gradle.org/gradle-download/
- Extract into the desired development directory, e.g., C:\Dev\Android\gradle-2.7.
- Add the Gradle bin directory to your PATH variable, e.g.: C:\Dev\Android\gradle-2.7\bin
- Restart your terminal window to fetch the updated PATH variable.
- You should now be able to build with: build -g
Android Studio Development Software Setup for Mac OS X
In order to develop Android applications, you must have the following software installed on your system:
- Xcode
- Java Development Kit (JDK)
- Android Studio
- Android Native Development Kit (NDK)
Gradle installation is recommended but not required. See Gradle for more information.
Xcode
Before installing any Android development tools, you must install Xcode.
Once installation is complete, some of the following steps (such as installing the JDK) may be unnecessary.
To download Xcode, visit https://developer.apple.com/xcode/download/
Java Development Kit (JDK)
Install the JDK if it is not already present on your system. If you have already installed Xcode, this step may be unnecessary.
The latest version tested with this release is JDK 8u45 - it may be downloaded at the following location: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html.
Android Studio
Download the Android Studio Bundle from the following location: https://developer.android.com/sdk/index.html
The Android Studio Development Bundle includes the basic tools you need to begin developing Java Android Applications:
- Android Studio IDE
- Android SDK tools
- Latest Android Platform
- Latest System Image for Emulator
Once downloaded, follow the install instructions located here: https://developer.android.com/sdk/installing/index.html?pkg=studio
Installing Additional Packages and Tools
You must download additional packages required by the Mobile SDK via the Android Studio SDK Manager, found in Tools > Android > SDK Manager. Android Studio may prompt you to take this step automatically the first time you launch it.
The following packages are required for native development:
- Android SDK 4.42. API level 19 or later
- Android Build Tools 22.0.1
The following optional packages under the SDK Tools tab in the SDK Manager are known to work with the Mobile SDK:
- Android SDK Tools 23.0.2
- Android SDK Platform-tools 20
- Android SDK Build-tools 20
More information about installing additional packages is found here: https://developer.android.com/sdk/installing/adding-packages.html
Android Native Development Kit (NDK)
The Android Native Development Kit (NDK) is a toolset that allows you to implement parts of your app using native code languages such as C and C++. It is used extensively by the sample applications which come with this release.
The latest version which has been tested with this release is NDK r10e - it is available for download at the following location: https://developer.android.com/tools/sdk/ndk/index.html.
Once downloaded, extract the NDK to your home/dev folder (~/dev). Your dev folder should look something like the following:
Note that Android Studio and the NDK are extracted into their own folders. These folders may be given any name you wish, but they must be installed into separate folders to avoid any conflict between the two packages.
You can read more about installation and use of the NDK here: http://developer.android.com/tools/sdk/ndk/index.html#installing.
Gradle
Gradle is a build automation suite used by our standalone build scripts and by Android Studio to manage dependencies and allow for custom build logic. Gradle replaces the previous Android build system, Ant, which is now deprecated for use in Android development.
It is not necessary to install Gradle to use the Mobile SDK. Oculus Mobile SDK 1.0+ build scripts use the Gradle Wrapper (gradlew), a small wrapper that automatically downloads and installs Gradle the first time you build a project. However, if you wish to install the full version of Gradle, we have included instructions.
The latest version which has been tested with this release is Gradle 2.7. Choose the Complete download if you want the Gradle source and offline documentation.
Manual Installation
- Download from http://gradle.org/gradle-download/ (requires version 2.5+)
- Extract into some common development directory. For example: ~/android/gradle-2.7
- Add the Gradle bin directory to your PATH variable. For example: ~/android/gradle-2.7/bin
- Open a new Terminal window to refresh the PATH variable.
You should now be able to build with: ./build.py -g Install using Brew:
Requires Brew, an optional package manager for OS X.
- Run sudo brew install gradle in the terminal.
- Open a new terminal window to refresh the PATH variable.
You should now be able to build with: ./build.py -g Install using MacPorts:
Requires MacPorts, an optional package manager for OS X.
- Run sudo port install gradle in the terminal.
- Open a new terminal window to refresh the PATH variable.
You should now be able to build with: ./build.py -g