Search code examples
xcodecordovaphonegapipa

Phonegap/Cordova to ipa file without Phonegap build


I use Phonegap Build to create my Android and iOS app files. However I want to compile the files locally on my computer, and not use Phonegap Build. I have done this successfully for Android (see here: https://cordova.apache.org/docs/en/latest/guide/platforms/android/) but iOS is more complicated. I have little Apple-knowledge.

Does anybody know of any good tutorials on how to import a Phonegap plugin in to the xcode environment...ideally one for someone who's background is NOT an Apple developer.


Solution

  • I have managed to do this myself but I've answered my own post to help others who may be in a similar situation - Please note this is correct as of end of 2019, and I had already successfully uploaded an IPA file to the app store via Phonegap Build before. All I'm doing here is compiling my Phonegap/Cordova project IPA file directly on a Mac, rather than using Phonegap Build:

    1) You will need a mac and a developer license (as expected). You will be using both a terminal window where possible and Xcode.

    2) Certificates and provisioning are a messy nightmare right out of satans bumhole. But just make sure you set up an "App store distribution" profile on your developer.apple.com account. If you don't know how to handle certificates and provisions please read here https://medium.com/ios-os-x-development/ios-code-signing-provisioning-in-a-nutshell-d5b247760bef. But remember you only need to download the certificate to your Mac, and add it to your "My Certificates" area. The provisions can be automatically downloaded/linked to via Xcode.

    3) Install Xcode 11 on your Mac. Forget all the other versions.

    4) Install Cordova CLI on your Mac using the terminal - open up the terminal window and type: sudo npm install -g cordova

    5) Create a FRESH cordova project - dont try to be smart by shoe-horning the one you've already used on your PC:

    cordova create hello com.example.hello HelloWorld ...you might need to to add "sudo" to the front of that. Don't copy and paste any html files or plugins in to it yet!

    6) If your Mac might give you read/write access problems. So locate the entire folder, ctrl+click on the project folder, choose "get info" ...in the bottom right of the popup window click the lock icon and enter your password. Now change all settings to "read and write", then click the cog icon and select "Apply to enclosed items".

    7) Create the platform : sudo cordova platform add [email protected]....note, DO NOT use ios5.1.1 if you are using firebase or push notifications, as it seems to break with 5.1.1.

    8) Apple will (again) probably give only read access to your new platforms/ios folder, because it hates you and wants you to suffer. So repeat step 6 if necessary.

    9) Open Xcode the following way... In your projectname/platforms/ios/ folder locate the .xcworkspace file. This is the file you use to open your project. DO NOT use the .xcodeproj file because this is for older Xcode versions (and it will just break your whole damn project). Also go to File->Workspace Settings and ensure Build System is set to "Legacy Build System".

    10) Now piece together your config.xml file by extracting the bits you need from your previous config file to your fresh new one. Don't bother moving over any android-specific bits.

    11 a) Apple bring you a fresh slice of hell with cocoapods - a dependency manager for Swift and Objective-C. You'll need to install this if your app uses certain things like push notifications (firebase for example). You can install this via the terminal window. FIRST....close down Xcode. NEXT go to projectname/ and type: sudo gem install cocoapods. FINALLY go to projectname/platforms/ios/ and type pod install.

    11 b) There's a bug...a pretty major one. Your cocoapods will fail when building at this point. So you need to do some hacking here. Navigate to the directory projectname/platform/ios/Pods/TargetSupport Files/Pods-yourproject and look for Pods-yourproject.debug.xconfig and Pods-yourproject.release.xconfig

    You need to copy the content of these files into platform/ios pods-debug-xconfig and pods-release.xconfig respectively----THANK YOU kyale-mwendwa for this tip....https://github.com/phonegap/phonegap-plugin-push/issues/1825#issuecomment-359155007

    12) Now copy and paste your www folder over in to your fresh project. You are ready to build your project...

    13) Re-open xcode using the .xcworkspace file. Now you need to ensure your provisioning is set up correctly for your release. Click the project name at the top of the left-hand column (right above where it says config.xml). Now in the main window click your app name under the "Targets" section. Now select "Signing and Capabilities". If you managed to set up certificates and provisions correctly you should be able to select your "team" (no I don't know either, just select whatever option you can here), and enter the correct bundle identified (com.whatever.whatever).

    14) Ok, you are ready to create your IPA file. Still have hair?? Bonus points for you!

    Just before this next bit, go to Xcode and towards the top of the screen you will see the project name followed by "> iPad (7th generation)" or something similar. Click this and make sure you choose "Generic iOS device".

    Now back in the terminal enter sudo cordova build ios. You don't have to transport your plugin files over from your windows-built cordova folder. Cordova will detect the plugins you need from your config.xml and install them appropriately.

    15) If you have no errors you can now create your IPA file and even submit it directly to the App store (this bit of Xcode is actually really good). In Xcode, from the menu at the top click "Product" and then "Archive". Follow the onscreen instructions. At this point your IPA file is created. You can choose to automatically distribute your file to the Appstore, but I suggest clicking the "Validate App" option first, which will re-request the correct certificates/provisions and give you a summary of any issues. If no issues you can click "Distribute App" and it will upload the IPA file to your Appstore Connect (formerly iTunes Connect) area.