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 Development Kit (SDK) with the relevant Android platforms, platform tools and build tools for your Project.

  3. 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.

  4. Download and install the Android Native Development Kit (NDK) if you are using the IL2CPP scripting back end.

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.

Refer to the Android scripting page of the Manual for more information.

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

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

To find out how to make these functions accessible from within Unity, visit the Android plug-ins page.

遮挡剔除

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

Refer to the Occlusion Culling Manual page for more information.

自定义启动画面

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

Refer to the Customizing an Android Splash Screen Manual page for more information.

故障排除和错误报告

The Android troubleshooting guide helps you discover the cause of bugs as quickly as possible. If, after consulting the guide, you suspect the problem is being caused by Unity, file a bug report following the Unity bug reporting guidelines.

See the Android bug reporting page for details about filing bug reports.

纹理压缩

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 or the Android supported media formats page.


Android
Android SDK/NDK setup