You set the Titanium SDK version to compile your app with in tiapp.xml. If it’s an Alloy app you can set the Alloy version to compile with. If you use the stand-alone Titanium CLI then it will use whatever version of the stand-alone Alloy CLI you have installed. If you use the unified Appcelerator CLI it will use the Alloy version that is embedded in the Appcelerator CLI Core Package that you have selected with appc use. Read Understanding the Unified Appcelerator CLI for more background on that.
Why would want to require specific versions?
Sometimes you will want to restrict your app to certain versions of the Titanium SDK and Alloy MVC. One example are our release sample apps. They are meant to be compiled using a specific Titanium minor version and generally require the latest Alloy version at the time of release.
When you import a sample app it will set the
tiapp.xml to the latest installed SDK if the one set cannot be found. And like we saw the Alloy version depends on the environment as well. So it might well be that the sample will fail to compile or run, leaving the developer in the dark on the reasons why.
How to do it?
So, after updating the Titanium 5.2 Sample App to take advantage of some new fixes and features Titanium 5.2.2.GA and Alloy 1.8.5, I added two simple scripts to make sure the app only compiles on those or later versions and provides helpful feedback when those requirements are not met.
Limit to a range of Titanium SDK versions
<plugins> <plugin version="1.0">ti.alloy</plugin> <plugin version="1.0">ti.version</plugin> </plugins> <property name="ti.version.range" type="string">>=5.2.2 <5.3</property>
NOTE: As you can we need to encode any special XML characters like
When someone compiles your app with an unsupported version it will fail with something like:
[INFO] Found Titanium plugin id=ti.version version=1.0 [ERROR] This app requires Titanium SDK >=5.2.2 <5.3 instead of 5.1.2.GA (5.1.2.v20151216190036)
Require a minimum Alloy version
For Alloy I’ve added a hook to app/alloy.jmk – the so-called Build Configuration File. This hook receives the minimum version we set in app/config.json and checks this against the Alloy version used to compile. If an older Alloy version is used it will fail with a message like:
[INFO] Found Alloy app in /Users/fokkezb/dev/samples/appc-sample-ti520/app [INFO] Executing Alloy compile: /usr/local/bin/node /Users/fokkezb/.appcelerator/install/5.2.2/package/node_modules/alloy/bin/alloy compile /Users/fokkezb/dev/samples/appc-sample-ti520/app --config platform=ios,version=0,simtype=none,devicefamily=universal,deploytype=development,target=simulator [INFO] [config.json] regenerating CFG.js from config.json... [ERROR] This app requires Alloy 1.8.5 or later instead of 1.7.35 [ERROR] Alloy compiler failed
NOTE: We don’t have access to the node-appc package in the context where
alloy.jmkis executed. I didn’t want to introduce a dependency which is why I use a simple helper method to convert a string version to an integer. This is why it only supports checking against a minimum version, not a range.
Code Strong! 🚀