Posts Tagged XCode

You know this journey starts with, “…I was so excited to get Mountain Lion and download the new Xcode.” I’m now absolutely shocked as for the first time, I’m faced with a strange and unique predicament. I cannot archive one of my commonly archived for Ad Hoc developer release iOS applications. What happened? Where did it start breaking? I’ll share the facts here and maybe, just maybe, this might help out some poor soul out there.

Let’s start by saying this, how do you even know you’re having this issue? The first sign of trouble is you build an archive file in Xcode for an “Ad Hoc” release. The last step finishes up with a code signing or “codesign” process and a final saving of the IPA file. Everything seems to work properly. You then do one of the following, install via iTunes or upload the IPA to Test Flight. All seems fine and grand. The trouble has just begun. Your users will begin reporting to you that they cannot download or worse they are seeing the “Failed to install” error. You’re already in this hole now… what is going on?

My first gut reaction was to start building another archive and then another and each one had the same issue. I finally realized that the Xcode Organizer tool was going to help me out. I did the install using iTunes on my iPad 3 and monitored the iPad 3 console in Organizer.

I can’t tell you how upsetting it was to see this error and to know that Xcode when archiving did not even make a peep about a code signing error. I quickly opened up my friendly terminal and located my IPA file that I had just attempted to install. I ran the famous command “codesign” and here is what it looks like.

Chris-Danielsons-MacBook-Pro-2:Desktop myUserAcct$ codesign -dvvv MySpecialApp.app
MySpecialApp.app: code object is not signed at all

So it’s clear to me that Apple has a fairly major issue on their hands that has seemingly let the user wander mindlessly into a trap thinking they were on a great journey of sorts.

So here is the question, how does one correct this issue? Continuing to fail miserably… here is what I have done thus far to attempt to correct the issue.

I have verified that all my certificates are in order. Deleted my mobile provisioning profiles manually, re-added them from the Apple developer portal.

Open Disk Utility and do a full verify and repair disk permissions.

Do a full shutdown and startup of my computer.

None of these processes have fixed this issue.

I finally figured out the solution by trial and error. In my case I had a folder name that matched the “Product Name” variable under build settings. This also matched the entire project name! So I simply changed one field. I changed the “Build Settings” -> “Product Name” . The value of MySpecialApp was changed to My-SpecialApp. That was simply it! I then logged back into the Apple developer portal and created a new App ID and mobile provisioning profiles for development and distribution and the rest is history. My releases now work when deployed via the Ad Hoc distribution.

A final note on this. This is definitely a bug that Apple should either alert the user that they have done something wrong and enable some sort of automated corrective action. After archiving I still receive:

codesign -dvvv My-SpecialApp.ipa
My-SpecialApp.ipa: code object is not signed at all

So what gives? Something is very wrong here, but this solution works for now.

Let me start off by saying that Unity3D is a really great game engine. Let me also say that I wish the documentation was as great as the engine is. Sadly, it’s difficult to figure out some of the more powerful features of Unity3D without significant trial and error.

Please note, that I have read that the usage of Assetbundles on the iPhone can be memory intensive and may or may not fit your needs per your project. I am just putting this information here so that others can see how to do this.Pro Tip: What this means to you? Profile the heck out of your code, pre-assetbundles and after integrating assetbundles.

Assumptions:
1. You know or are familiar Unity3D 3.3.
2. You can code in C#.
3. You’re an ace at creating prefabs in Unity.
4. You’re using Unity3D 3.3 Pro and iOS Pro.

OK, if you’re still feeling good, let’s bounce into this how-to.

Create the Project

Open up a new project in Unity3D and set it up for “iPhone” iOS. Feel free to name it whatever passes your way.

Hit save after doing this and save your default scene and name it whatever you want. In my case, I named it “test”.

Though, this is a near complete looking example (image to the right), the basic structure should look like the image to the right here.

Add at least one prefab to your project. I have added two prefabs here, “box” and “ABCD”. Both are just tests and contain a cube prefab with a simple texture applied. Make sure that the materials referenced by your prefabs have the following attributes. 1. They are named the same as the prefab. (See the image above!). 2. They are stored in the materials folder underneath the iphone folder.

UnityEditor Coding Time

When working on assetbundles, the first thing you have to do is generate them. Unfortunately, Unity3D does not have anything built in for generating these files except for a UnityEditor API. The UnityEditor script can only be run from inside the Unity3D editor tool. It typically appears as a menu item after the script has been successfully compiled. So if you can code, then you’re in good shape.

Let’s create the UnityEditor script. Create a new C-Sharp script in a /Plugins/ folder (create it if it doesn’t already exist) at the root of your project and name it MPCreateAssetBundle. Copy and paste the following into it. Please note: some of this code was borrowed from Unity’s own Character Customization tutorial on their website.

Once this is completed, you’ll want to do two things.
1. Select (by moving your mouse over and left-clicking on it once) the iphone folder under “Example Project”.
2. Run the script as shown in the image:

So let’s back up for a second and look at what we just did. We created a project, created some folders within the project, placed prefabs into the iphone folder and created a UnityEditor script. Upon running this script, a new directory named “assetbundles” would be created.
This directory is not going to be visible to you until you open finder (on Mac) or explorer (on Windows) as it is located on the file system. (see the image above). Inside this folder you should see your prefab(s) named now as: iphone-prefab-<my prefab name>.assetbundle. If you are seeing this, congratulations, you’ve now created your own assetbundles uniquely per prefab.

Generic GameObject and a Simple Script

If you’ve come this far, great work! We’re nearly done.
Let’s create a new GameObject under the Hierarchy.

Now we’re going to write a simple script to instantiate the assetbundles we assembled earlier. Create a new C-Sharp script in the /Plugins/ folder and name it “Example”. Copy and paste the following code into it:

Build Time

We’re now going to build this codebase so that you can run it on your iOS device for testing. I’m going to skip the painful steps of creating a code signing certificate and all that jazz. We’re instead going to focus on how to get the actual assetbundle onto your iOS device in an area that will be accessible to the “Application.dataPath” call in your code!

1. Build the Unity project for iOS.
2. XCode should automatically open.
3. Within XCode you are going to need to tell it about your assetbundles folder! Open up finder or explorer and locate the assetbundles folder that was generated by the UnityEditor script we discussed earlier.
4. Drag and drop the assetbundles folder into XCode at the root of the iOS project. (You should see a prompt as follows)

5. Click “Finish”.

This will then look something like this:

6. Build the code using XCode and run it on your iOS device.

If everything works properly, you should see one of the prefabs instantiate on your iOS screen. That is all there is to it! I think you’ll find that this isn’t as bad as one might imagine, but it does require some serious fishing around in code examples and heavily crawling the Unity forums. The only way I figured this out was by trial and error, heavy amounts of Debug.Log calls and 3 pots of coffee. I’m now going to go and grind my teeth on my level editor.

Edit: I have one of my original forum posts here as well regarding this issue. Unity3D Forum

This is just to help those that have run into a whole slew of linking and other errors when attempting to add the cocos2d and Box2d frameworks directly into your project.

This information is pertinent for:

#define COCOS2D_VERSION 0x00009904

Cocos2d is easy enough to get to compile into your project. Dealing with Box2d is entirely more complicated if you don’t understand how the file inclusions work. Because of the location of the Box2D.h file you’ll quickly find yourself in a nearly endless conundrum of mismapped linking…

Here is how my project is currently setup:

Cocos2D with Box2D Project Groups

As you can see I have created the Box2D and Cocos2D directories as groups.

The actual file system looks like (I created the lib folder):

/Users/chris/Documents/iphone_apps/myCocos2DProject/lib

which contains the following directories copied directly from the cocos2D download source package: cocos2d and external

Take careful note that I have removed the “TestBed” in order to avoid the missing “glui.h” issues!

So even with this setup I still was receiving over 5000 nasty Box2D errors. Here is the fix I found to work.

==========================

==========================

Go to Project -> Edit Active Target “myCocos2DProject”

Select the Build tab.

Edit XCode Project Settings

Check the “Always Search User Paths“

And add in the “lib/external/Box2d/**” into the “User Header Search Paths” Pro Tip: When adding the header search paths, make sure that you have the recurse check box selected.

That is all you have to so to fix the issue!

One final super pro tip: Make sure that your .m files are renamed to .mm in order to get the C++ libraries working. You will have to rename the AppDelegate_iPhone.m to AppDelegate_iPhone.mm. (Otherwise you’ll see errors like: cassert no such file or directory, etc.)

About Me

I'm a software developer focused on all facets of enterprise solutions and technologies. Currently I code Scala, Java, Swift, Objective-C, .Net, to name a few. My latest endeavor is LogVine. We're soon moving from micro-log to a new sustainable living framework and feature set.