Monday, February 16, 2015

Corona SDK and Code Signing

It's been forever since I posted anything here. A lot has happened since I last posted. I left my old 9-5 to start an agile training, coaching, and consulting company called Artemis Agile Consulting. A LOT of my effort has been focused on trying to get that moving forward. As a result, I've been working in my "copious free time" on games. I ran into some problems with OttoJotts that I was having a REALLY hard time solving so I decided to take a break, get some fresh perspective, and work on something simple that's based on an idea my daughter had.
Basic app with VERY placeholder graphics
The game I'm working on right now is called Cats and Dogs. You play a secret agent cat or dog trying to prevent a bad guy from taking over the world. It's quite simple, in a Flappy Bird kind of way, but I hope it will be enjoyable. And silly. Silly is the key. I decided to try Corona SDK as my app bed because it allows multi-platform support. I really don't want to learn Java at this point in my career, so this seemed like a good solution.
I've had success with Corona in the past. I wrote a simple app to help developers on my teams at the old 9-5 estimate story points using a Magic 8-Ball. You'd shake your device and it would show you an estimate - anything from 1/2 to infinity using a modified Fibonacci sequence. They had complained about "how hard it is to estimate", so I made it easier for them. And we laughed about it. But the experience was great - everything worked seamlessly for both Android and iOS and I was happy.
I've been working on Cats and Dogs for a few months off-and-on and decided that it might finally be in a place where I could put it on my daughter's phone for her to play with. It's nowhere near "done", but it's enough that she can at least play it. So I began the process to build it for iOS and get it going. And that's when I ran into the dreaded "The application does not have a valid signature" issue in Xcode. This is a common error based on the number of stackoverflow questions about it.
Corona has quite a lot of documentation about how to build your application using their simulator. There are also quite a few gotchas. Corona lists several things that can prevent your app from installing on your device: expired profiles, spaces in your project name, etc.
First, let me say that I was using the Xcode Devices window to install the application. I tried iTunes, which seemed to work, but after it put the app on the device it greyed out the icon saying it was "Installing" - iOS speak for "not gonna work, broh". Second, I was using a version of the SDK from November but downloaded the new version (2511) in the process. DO download the new version - the shell console makes it worth it.
For me, I had made sure that I created new certificates for both development and distribution - it had been a while and was worth refreshing everything. Then I created App IDs for both dev and distro and then provisioning profiles. Everything looked shiny and new. I had some old profiles that had expired, but as I wasn't using them anymore, it didn't seem like a big deal. I thought I was pretty much golden.
When I built the app, I made sure I was using the development profile and provisioning profile. Looked like everything was happy when it built but when I tried to install it I got the "Application does not have a valid signature" problem. If you right-click on the device in Xcode it will show you what profiles are installed - and all four of the new ones were, so I was confused.
After I began exploring the issue, I saw a couple of things that might be causing problems. First, I had expired profiles. So I followed the directions and deleted them from ~/Library/MobileDevice/ProvisioningProfiles (the shell console will show you the expired profile IDs). But if you got into Xcode | Preferences and refresh your profiles from iOS Developer Center, it will simply re-download them, which doesn't do you any good. So what I did - unnecessarily, I believe - was to edit all of my expired profiles and renew them. Rebuild, re-install, failure. So it wasn't that.
Then I found that you can't have spaces in the project name. I was using "Cats and Dogs" as my folder for my project, so I made a new folder called "CatsAndDogs" and tried it. Rebuild, re-install, re-fail. Check that one off the list.
I went through the shell console and noticed that it tells you what it actually puts into the bundle. I've been using an Excel spreadsheet to check some things and saw, in the build, that it was putting my Excel sheet in the app. Say what? So - let's remove that from the source folder and try again. Rebuild, re-install, re-fail. Okay - so, not that.
More searching, more looking at parts of my app and source and folders. Nothing. Then I decided to see if it was my project or if it was iOS Developer stuff and I opened the Hello World sample. Build, install, fail. Aha! So it's not my project, it's my provisioning profiles somewhere...
One of the threads I read say to go through your keychain and remove old profiles. I searched for "iPhone" and found a few items but now something stuck out a little. I had two Developer profiles. So I went to iOS Developer Center and downloaded my brand-spankin'-new developer certificate, removed both certs from keychain, and then reinstalled the new one. Then - rebuild, reinstall, and - success!
So, what worked for me (for development, at least) was to remove my old certificates and install my new ones. If you're still running into problems and don't have a "resources" folder in your project, don't have spaces in your project name, and aren't using expired profiles, maybe delete your certificates and install ones freshly-downloaded from iOS Dev Center. Hopefully it works for you!