Skip to content

Instantly share code, notes, and snippets.

@tonylukasavage
Created June 2, 2014 14:51
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tonylukasavage/a87834dd4e1be4640c29 to your computer and use it in GitHub Desktop.
Save tonylukasavage/a87834dd4e1be4640c29 to your computer and use it in GitHub Desktop.
Inject environment variables into Titanium. Makes shared code easier to manage (no more sanitizing keys in repos). Uses Titanium to encrypt the values.
// now you can use it in a titanium app
useSomeApi(Ti.App.Properties.getString('SOME_API_KEY'));
exports.init = function (logger, config, cli, appc) {
cli.addHook('build.pre.compile', function(build, done) {
// inject the environment variable straight into the tiapp. By doing this prior to compiling,
// it will be encrypted and made available via Ti.App.Properties.getString()
cli.tiapp.properties.SOME_API_KEY = { type: 'string', value: process.env.SOME_API_KEY };
done();
});
};
@manumaticx
Copy link

How could you inject a Google Maps API Key into the android manifest part of tiapp.xml ?

@sachinkumarsharma
Copy link

Hi Tony ,
I am also trying to create build for QA and Production with differnt Tiapp Configuration , In above example , i can not find the the way to call init , and it's argument. Do we need to call init explicitly or it gets called implictly.
I have added above init function in alloy.jmk file but it never gets called.

Please suggest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment