While performing the build with Appcelerator SDK 5.5.1.GA, after invoking xcodebuild it throws an error with the text cannot read property 'emit' of null. It used to work fine till last week. It is only occurring when I am making an AdHoc or Production IPA. It is launching in emulator without any issue.
It is happening if I do it thorough both Studio or using console. If anyone from the community has faced this issue can you please let me know. If I am using older SDK like 5.5.0.GA then the build is working fine.
XCode: 7.3.1 Node: 0.12.7
Apart from the above process which have been mentioned by my fellow developers, following too will work without making any changes in the environment. This would require the 2-phase build.
For reference let us use this link for reference: Appcelerator iOS Build JS (_build.js)
To resolve this issue you can initiate the build from the terminal
appc run --build-only -T dist-adhoc --project-dir ~/Code/MyApp
Once the build is initiated, let it go through and wait till
invoking xcode
is called and throws the error. Once the error is thrown, go to the following folder:
build/iphone/build/Products/Releases-iPhone
Inside there you will find the APP file and the DSYM file. If not, wait for 2-3 minutes and the background process for XCode build will be done. Once you see these two files, open the _build.js for the SDK (5.5.1.GA) in this case. You can find the path being displayed in the console during the beginning of the build.
Open the _build.js file and go to the following function
iOSBuilder.prototype.run = function (logger, config, cli, finished)
Inside there you will find a series which has all the function call. In here you need to make the following changes:
function (next) {
cli.emit('build.pre.construct', this, next);
},
// initialization
//'doAnalytics',
'initialize',
'loginfo',
//'readBuildManifest',
//'checkIfNeedToRecompile',
//'initBuildDir',
/*
function (next) {
cli.emit('build.pre.compile', this, next);
},
function () {
// Make sure we have an app.js. This used to be validated in validate(), but since plugins like
// Alloy generate an app.js, it may not have existed during validate(), but should exist now
// that build.pre.compile was fired.
ti.validateAppJsExists(this.projectDir, this.logger, ['iphone', 'ios']);
},
// xcode related tasks
'createXcodeProject',
'writeEntitlementsPlist',
'writeInfoPlist',
'writeMain',
'writeXcodeConfigFiles',
'copyTitaniumLibraries',
'copyTitaniumiOSFiles',
'copyExtensionFiles',
'cleanXcodeDerivedData',
// titanium related tasks
'writeDebugProfilePlists',
'copyResources',
'encryptJSFiles',
'writeI18NFiles',
'processTiSymbols',
// cleanup and optimization
'removeFiles',
'optimizeFiles',
// provide a hook event before xcodebuild
function (next) {
cli.emit('build.pre.build', this, next);
},
// build baby, build
'invokeXcodeBuild',
*/
// provide a hook event after xcodebuild
function (next) {
cli.emit('build.post.build', this, next);
},
// finalize
'writeBuildManifest',
function (next) {
if (!this.buildOnly && (this.target === 'simulator' || this.target === 'device')) {
var delta = appc.time.prettyDiff(this.cli.startTime, Date.now());
this.logger.info(__('Finished building the application in %s', delta.cyan));
}
cli.emit('build.post.compile', this, next);
},
function (next) {
cli.emit('build.finalize', this, next);
}
Now again run the appc run command. Now this is going to take the last build and prepare the IPA out of it. This is a long process but gets the work done without any environment changes.