# How TEngine Handles Platform-Specific Differences for iOS and Android

> Discover how TEngine manages iOS and Android differences using Unity preprocessor directives and helper methods for seamless cross-platform development. Learn more.

- Repository: [ALEX/tengine](https://github.com/alex-rachel/tengine)
- Tags: how-to-guide
- Published: 2026-02-24

---

**TEngine abstracts iOS and Android disparities using Unity's compile-time pre-processor directives (`#if UNITY_IOS`, `#if UNITY_ANDROID`) alongside centralized helper methods that handle platform name resolution and file path conversion.**

TEngine is a Unity-based game framework that maintains cross-platform compatibility while addressing the distinct file system behaviors of mobile operating systems. According to the alex-rachel/tengine source code, the engine isolates platform-specific logic in dedicated helper classes, ensuring the majority of the codebase remains platform-agnostic while critical low-level differences are handled through conditional compilation.

## Platform Name Resolution with UpdateSetting

The engine identifies the current runtime platform through the `GetPlatformName()` method in [`UnityProject/Assets/TEngine/Runtime/Core/UpdateSetting.cs`](https://github.com/alex-rachel/tengine/blob/main/UnityProject/Assets/TEngine/Runtime/Core/UpdateSetting.cs). This method returns standardized strings used to construct download URLs and select platform-specific assets.

At lines 84-91, the implementation uses pre-processor directives to determine the active platform:

```csharp
// Returns "IOS" on iOS builds, "Android" on Android builds
string platform = UpdateSetting.GetPlatformName();

```

When `UNITY_IOS` is defined, the method returns `"IOS"`; when `UNITY_ANDROID` is defined, it returns `"Android"`. This string becomes a critical component in `GetResDownLoadPath()` and `GetFallbackResDownLoadPath()` (lines 66-71), which concatenate the base server URL with the platform identifier to generate appropriate download endpoints.

## File Path Conversion for StreamingAssets

The most significant platform divergence occurs in how Unity accesses the `StreamingAssets` folder. In [`UnityProject/Packages/YooAsset/Runtime/DownloadSystem/DownloadSystemHelper.cs`](https://github.com/alex-rachel/tengine/blob/main/UnityProject/Packages/YooAsset/Runtime/DownloadSystem/DownloadSystemHelper.cs), the `ConvertToWWWPath()` method (lines 49-57) transforms local file system paths into URL schemes compatible with `UnityWebRequest`.

**iOS handling** uses the standard `file://` scheme because iOS treats StreamingAssets as regular files:

```csharp
// iOS result: "file://<full-path>/config.json"
string wwwPath = DownloadSystemHelper.ConvertToWWWPath(localPath);

```

**Android handling** requires the `jar:file://` scheme to access assets packaged inside the APK:

```csharp
// Android result: "jar:file://<full-path>/config.json"
string wwwPath = DownloadSystemHelper.ConvertToWWWPath(localPath);

```

This distinction is essential because Android APKs store assets in a compressed archive that behaves differently from a standard file system.

## Conditional Compilation Strategy

Beyond runtime helpers, TEngine uses compile-time symbols to strip platform-specific editor code from mobile builds. The source code wraps editor-only initializations and platform-specific logic in guards such as `#if UNITY_IOS || UNITY_IPHONE` and `#if UNITY_ANDROID`.

This pattern appears in [`UpdateSetting.cs`](https://github.com/alex-rachel/tengine/blob/main/UpdateSetting.cs) and [`DownloadSystemHelper.cs`](https://github.com/alex-rachel/tengine/blob/main/DownloadSystemHelper.cs), ensuring that platform-specific branches compile only for their respective targets. The approach eliminates runtime branching overhead for platform detection and prevents editor-specific code from bloathing mobile builds.

## Runtime Workflow Integration

The platform abstraction operates through a four-stage workflow:

1. **Platform Detection**: At runtime start, `UpdateSetting.GetPlatformName()` establishes the human-readable platform identifier.
2. **URL Construction**: `GetResDownLoadPath()` builds the server URL by appending the platform name (e.g., `http://127.0.0.1:8081/Demo/Android`).
3. **Path Conversion**: When loading resources locally, `DownloadSystemHelper.ConvertToWWWPath()` receives the file path and returns the appropriate URL scheme (`file://` for iOS, `jar:file://` for Android).
4. **Network Request**: UnityWebRequest consumes the formatted URL, which matches the platform's file system expectations.

## Editor Build Post-Processing

TEngine extends its platform handling into the Unity Editor through separate post-process scripts:

- [`UnityProject/Assets/TEngine/Editor/Localization/PostProcessBuild_IOS.cs`](https://github.com/alex-rachel/tengine/blob/main/UnityProject/Assets/TEngine/Editor/Localization/PostProcessBuild_IOS.cs) handles iOS-specific build configurations
- [`UnityProject/Assets/TEngine/Editor/Localization/PostProcessBuild_ANDROID.cs`](https://github.com/alex-rachel/tengine/blob/main/UnityProject/Assets/TEngine/Editor/Localization/PostProcessBuild_ANDROID.cs) manages Android-specific build adjustments

These scripts run during the build pipeline to modify platform-specific project settings, complementing the runtime abstractions with build-time configuration.

## Summary

- **Centralized platform logic** resides in [`UpdateSetting.cs`](https://github.com/alex-rachel/tengine/blob/main/UpdateSetting.cs) (platform naming) and [`DownloadSystemHelper.cs`](https://github.com/alex-rachel/tengine/blob/main/DownloadSystemHelper.cs) (path conversion).
- **URL scheme differentiation** uses `file://` for iOS and `jar:file://` for Android to accommodate their distinct asset packaging systems.
- **Compile-time guards** (`#if UNITY_IOS`, `#if UNITY_ANDROID`) isolate platform-specific code paths without runtime overhead.
- **Standardized workflow** combines platform name resolution with download path construction to support seamless cross-platform asset delivery.

## Frequently Asked Questions

### How does TEngine handle platform detection without runtime performance penalties?

TEngine leverages Unity's pre-processor directives (`#if UNITY_IOS`, `#if UNITY_ANDROID`) to resolve platform identity at compile time rather than runtime. The `GetPlatformName()` method returns a constant string based on the active compilation symbol, resulting in zero runtime branching overhead for platform detection while ensuring only platform-relevant code paths exist in the final binary.

### Can TEngine's platform abstraction handle custom Android APK paths or iOS bundle structures?

The current implementation in `DownloadSystemHelper.ConvertToWWWPath()` automatically adjusts for standard Unity StreamingAssets locations using the `jar:file://` scheme for Android and `file://` for iOS. While the helper methods are designed for Unity's default export structures, the centralized architecture in [`UpdateSetting.cs`](https://github.com/alex-rachel/tengine/blob/main/UpdateSetting.cs) allows developers to extend `GetResDownLoadPath()` to accommodate custom bundle layouts or additional path segments without modifying the core download system.

### Does TEngine maintain separate asset bundles for iOS and Android platforms?

No, TEngine uses the same asset bundles across both platforms. The differentiation occurs at the download and path resolution layer. As implemented in [`UpdateSetting.cs`](https://github.com/alex-rachel/tengine/blob/main/UpdateSetting.cs), platform-specific URLs (containing `/IOS/` or `/Android/` segments) point to platform-appropriate hosting locations, while the underlying asset bundle format remains identical. This approach minimizes storage redundancy while respecting platform-specific content delivery requirements.

### Which Unity versions support TEngine's conditional compilation approach?

The platform directives (`UNITY_IOS`, `UNITY_ANDROID`) utilized in TEngine are standard Unity pre-processor symbols available in Unity 5 and all subsequent versions including Unity 6. The `UnityWebRequest` API referenced in [`DownloadSystemHelper.cs`](https://github.com/alex-rachel/tengine/blob/main/DownloadSystemHelper.cs) requires Unity 5.4 or newer, though TEngine's use of these patterns remains compatible with current Long Term Support (LTS) releases.