Share One Alloy Codebase Across iOS and Android With Platform-Specific Views
Use Alloy platform folders to keep one mobile codebase while rendering native UI differently on iOS and Android. Verify SDK support before greenfield use.
06 Nov 2025, 03:38 UTC

The problem: one codebase, two native UI languages
You are maintaining a Titanium mobile app and need the same screen to look right on iOS and Android. Writing separate controllers for each platform duplicates business logic, but a single XML view cannot easily express platform-specific navigation bars, tab styles, or button behavior. Appcelerator's Alloy MVC framework offers a build-time solution: platform-specific directories that compile into native Titanium API calls without splitting your JavaScript controllers.
How Alloy separates shared code from platform UI
Alloy is Appcelerator's official MVC layer for Titanium SDK. It compiles XML views, TSS stylesheets, and JavaScript controllers into Titanium API calls before the CLI packages a native binary. The key directories are:
app/controllers— shared JavaScript that binds to view IDs and handles events.app/views— XML markup describing the UI hierarchy.app/styles— TSS rules that map to Titanium style properties.app/platform/iosandapp/platform/android— overrides used only when building for that OS.
When you build for iOS, Alloy merges app/views/index.xml with any matching file in app/platform/ios/views. Android does the same from app/platform/android. Controllers and models remain shared unless you deliberately place platform-specific copies.
Worked example: platform-specific button styling
Suppose you want a primary button that uses iOS system styling on iPhone and a distinct color scheme on Android. Start by scaffolding a project:
# Run in your terminal, inside the directory where you want the project.
# Requires read/write access to the folder. Replace <myapp> with your project name.
alloy new <myapp>
cd <myapp>
Create a shared view at app/views/index.xml:
<Alloy>
<Window>
<Button id="primaryButton" title="Save" />
</Window>
</Alloy>
Add shared styling in app/styles/index.tss:
"#primaryButton": {
width: 200,
height: 44,
top: 20
}
Now override the button style per platform. For iOS:
# File: app/platform/ios/styles/index.tss
"#primaryButton": {
backgroundColor: "#007aff",
color: "#ffffff"
}
For Android:
# File: app/platform/android/styles/index.tss
"#primaryButton": {
backgroundColor: "#6200ee",
color: "#ffffff"
}
Compile to inspect the generated Titanium code:
# Run from the project root. Normal user permissions are sufficient.
alloy compile
Expected check: Alloy should generate Titanium code from your XML and TSS without syntax errors. If compilation fails, the error usually names the XML or TSS file, though runtime stack traces may later point to generated Titanium code rather than your original Alloy files.
Trade-offs and limitations
- Compilation indirection: Because Alloy generates Titanium code, debugging can require mapping a runtime error back to the original XML or controller.
- Native knowledge still required: Platform folders do not remove the need to know which Titanium UI properties exist on iOS versus Android.
- Support status: Appcelerator's publishing activity and long-term support commitments have varied. Confirm current SDK health and version compatibility before starting a greenfield project.
Verify before you commit
- Run
alloy --versionandti --versionin the Appcelerator CLI to confirm installed versions. - Scaffold a test app with
alloy new, add one platform-specific style, and runalloy compileto confirm the override is picked up for the target OS. - Check Appcelerator's official Titanium SDK and Alloy documentation or repository for the support matrix matching your SDK version.
Platform folders are a practical way to share controllers while respecting native UI conventions, but they are only worth adopting if the toolchain is actively supported for your target versions.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.