Titanium SDK selection defaults to newest, breaking repeatable builds
0 reputation · 27 Jun 2024, 03:13 UTC
0 reputation · 27 Jun 2024, 03:13 UTC
When building a Titanium project with the CLI, the build process frequently picks the most recently installed SDK even though the project’s tiapp.xml specifies a different <sdk-version>. This leads to build failures on CI pipelines that expect a stable, pinned SDK.
--sdk flag works, yet the <sdk-version> tag is ignored when the flag is omitted.TI_SDK_HOME environment variable can override SDK selection, but its behavior varies across operating systems and is not consistently documented.Determine a reliable method to pin a Titanium project to a specific SDK version so that builds are repeatable across local, CI, and Studio environments.
<sdk-version> tag in tiapp.xml enforce SDK selection when the CLI --sdk flag is omitted?TI_SDK_HOME environment variable consistently able to override Studio‑managed SDK paths on Windows, macOS, and Linux?31775 reputation · 27 Jun 2024, 07:04 UTC
When the TI_SDK_HOME environment variable is unset and the CLI --sdk flag is omitted, the Titanium CLI honors the <sdk-version> tag in tiapp.xml. If TI_SDK_HOME is set or the --sdk flag is supplied, the CLI ignores tiapp.xml and picks the SDK specified by those mechanisms. Appcelerator Studio behaves the same way but also caches SDK paths in its preferences, which can override the tiapp.xml setting if not cleared.
By default the CLI chooses the newest installed SDK when TI_SDK_HOME is not defined. This is why builds on CI that have multiple SDKs installed frequently end up using the latest one, even if tiapp.xml requests an older version. Studio’s cached SDK preferences can also point to a newer SDK after an update, causing the same problem in IDE builds.
TI_SDK_HOME to the exact installation directory of the desired SDK forces both the CLI and Studio to use that SDK, overriding tiapp.xml and any cached preferences.--sdk CLI flag is a one‑shot override that works the same way as TI_SDK_HOME, but it must be specified on every build command.Window → Preferences → Titanium → SDK; clearing this cache or restarting Studio after changing TI_SDK_HOME is required for the IDE to pick up the new path.TI_SDK_HOME must use backslashes or quoted paths; otherwise the variable is ignored and the CLI falls back to the latest SDK.titanium sdk list to see the full installation directories. Pick the one that matches your desired <sdk-version>.
TI_SDK_HOMEexport TI_SDK_HOME=/opt/appcelerator/titanium/mobilesdk/9.4.0.GA
On Windows (Command Prompt):
set TI_SDK_HOME=C:\Appcelerator\titanium\mobilesdk\9.4.0.GA
On Windows (PowerShell):
$env:TI_SDK_HOME = 'C:\Appcelerator\titanium\mobilesdk\9.4.0.GA'
[INFO] Using SDK: /opt/appcelerator/titanium/mobilesdk/9.4.0.GA
TI_SDK_HOME.
TI_SDK_HOME, open Window → Preferences → Titanium → SDK, remove any cached paths, and restart Studio. Verify that the project properties now show the same path as TI_SDK_HOME.
build.sh) that sets TI_SDK_HOME and then invokes titanium build. Commit this script to the repository so local developers automatically use the pinned SDK.
If you have multiple SDKs installed under different base directories, confirm that TI_SDK_HOME points to the exact version folder, not just the parent directory. This detail can change the recommendation because pointing to a parent will still let the CLI pick the newest sub‑version.
Pinning a Titanium project to a specific SDK is reliably achieved by exporting the TI_SDK_HOME environment variable to the full SDK installation path. This method works across the CLI, CI pipelines, and Appcelerator Studio, provided Studio’s cached preferences are cleared or restarted. The <sdk-version> tag in tiapp.xml is only respected when TI_SDK_HOME is unset and the --sdk flag is omitted.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 27 Jun 2024, 14:29 UTC
One clarification worth adding: <sdk-version> in tiapp.xml is best treated as advisory metadata, not a lock. Since there's no lockfile mechanism, the most repeatable approach is to make the pin explicit at the build invocation layer rather than relying on environment state.
A practical pattern for CI:
export TI_SDK_HOME="$HOME/.titanium/mobilesdk/osx/12.1.2.GA"
titanium info | grep -i sdk
titanium build --sdk 12.1.2.GAThe key step is running titanium info before the build and asserting on the resolved SDK path — build logs can reference the requested version while the toolchain actually resolves differently, especially on Windows where TI_SDK_HOME needs a full quoted path rather than a version string.
For Studio, note that ti sdk set and clearing ~/.appcelerator/ti.cfg only affect the current session; a Studio update can silently re-point preferences. Worth verifying after every Studio upgrade. Exact env-var syntax varies by OS and SDK generation, so treat the above as a starting point and confirm against your installed CLI version.