Version: 2017.2
Android
Android SDK/NDK setup

Android 开发入门

Building games for Android devices requires an approach similar to that for iOS development. However, the hardware is not completely standardized across all devices, and this raises issues that don’t normally appear during development for iOS.

Setting up your Android development environment

You need to have your Android development environment set up before testing your Unity applications on your Android device. Setting up your Android development environment involves the following steps:

  1. Download and install the Java Development Kit (JDK).

  2. Download and install the Android Software command line tools.

  3. From the command line tools, use the sdkmanager to install the platform tools, build tools, and Android SDK versions required for your Project.

  4. Connect your device to your computer. The setup process differs for Windows and macOS, and is explained in detail on the Android developer website. Refer to your device manufacturer for specific information about connecting it to your computer.

  5. If you are using the IL2CPP scripting back end, download and install the Android Native Development Kit (NDK)

The Unity Manual contains a basic outline of the tasks that must be completed before you are able to run code on your Android device, or in the Android emulator. However, the best thing to do is follow the instructions step-by-step from the Android developer portal.

Unity verifies your development environment when building for Android, and prompts you to upgrade or download missing components if necessary. Always use the latest tools available unless a specific version is required by Unity.

Access Android functionality

Unity provides scripting APIs to access various input data and settings from Android devices.

请参阅本手册的 Android 脚本页面以了解更多信息。

将原生 C、C++ 或 Java 代码暴露给脚本

可使用插件直接从 C# 脚本调用使用 C/C++ 编写的 Android 函数(可间接调用 Java 函数)。

要了解如何使这些函数在 Unity 中可访问,请访问 Android 插件页面

遮挡剔除

Unity 支持遮挡剔除,这是一种对移动平台非常有价值的优化方法。

请参阅本手册的遮挡剔除页面以了解更多信息。

自定义启动画面

The splash screen displayed while the game launches is customizable on Android.

请参阅本手册的自定义 Android 启动画面页面以了解更多信息。

故障排除和错误报告

Android 故障排除指南可帮助您尽快发现错误原因。如果在查阅指南后怀疑问题是由 Unity 引起的,请根据 Unity 错误报告指南提交错误报告。

请参阅 Android 错误报告页面了解有关提交错误报告的详细信息。

纹理压缩

ETC is the standard texture compression format on Android.

所有当前的 Android 设备都支持 ETC1 版本,但该版本不支持具有 Alpha 通道的纹理。所有支持 OpenGL ES 3.0 的 Android 设备都支持 ETC2 版本。该版本可提供改进的 RGB 纹理质量,并且还支持具有 Alpha 通道的纹理。

默认情况下,Unity 对压缩的 RGB 纹理使用 ETC1,而对压缩的 RGBA 纹理使用 ETC2。如果 Android 设备不支持 ETC2,则纹理将在运行时解压缩。这会对内存使用产生影响,也会影响渲染速度。

DXT、PVRTC、ATC 和 ASTC 全都支持具有 Alpha 通道的纹理。这些格式还支持更高的压缩率和/或更好的图像质量,但仅在一部分 Android 设备上受支持。

可针对这些格式中的每种格式创建单独的 Android 分发存档 (.apk),并让 Android Market 的过滤系统为不同的设备选择正确的存档。

Movie playback

Movie textures are not supported on Android, but full-screen streaming playback is provided via scripting functions.

To learn about supported file formats and scripting API, consult the Movie Texture page.


  • 2017–05–25 页面已发布并进行了编辑审查

  • 5.5 版中的更新功能

Android
Android SDK/NDK setup