Specific configuration for Ad Hoc builds

Both dist-appstore and dist-adhoc builds set deploy-type to production. In Alloy, this will trigger production-specific code in controllers, views, styles and config.json to be included. There is a ticket requesting a directive that would allow to also code for a specific distribution method, which is currently set to be fixed in Alloy 1.4.

Use case

This new directive would not make much sense in views and styles, but it would in controllers and config.json. For example, if you distribute an adhoc build to your testers via TestFlight, you might want to use different API keys and endpoints (e.g. push) or even add a feedback-button the menu.


While we wait for this to be added in Alloy 1.4, here’s a simple workaround.


Under env:production, use a property like dist to switch between distribution types. Make sure another property exists for each of the distribution types you need to set specific properties for.

	"global": {},
	"env:development": {
		"apiKey": "DEV123"
	"env:production": {
		"dist": "adhoc",
		"dist:adhoc": {
			"apiKey": "HOC123"
		"dist:appstore": {
			"apiKey": "STORE123"


Now simply extend the compiled Alloy.CFG with the appropriate property.

if (Alloy.CFG.dist && Alloy.CFG['dist:'+Alloy.CFG.dist]) {
	_.extend(Alloy.CFG, Alloy.CFG['dist:'+Alloy.CFG.dist]);
	delete Alloy.CFG['dist:'+Alloy.CFG.dist];

Conditional code

In controllers, simply switch using Alloy.CFG.dist. In views and styles use Alloy.CFG for values that are specific to the distribution type.

App imagineer: Imagining, Engineering & Speaking about Native mobile Apps with Appcelerator Titanium & Alloy • Meetup organizer • Certified Expert • Titan