Posts Tagged XCode

codesign IPA and the code object is not signed at all problem

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.

Aug 28 21:07:55 unknown installd[7066] <Error>: unrecognized status -67068 from codesigning library
Aug 28 21:07:55 unknown installd[7066] <Error>: 00403000 verify_signer_identity: Could not copy validate signature: -402620415
Aug 28 21:07:55 unknown installd[7066] <Error>: 00403000 preflight_application_install: Could not verify executable at /var/tmp/install_staging.6ua8Zg/foo_extracted/Payload/MySpecialApp.app
Aug 28 21:07:55 unknown com.apple.itunesstored[7074] <Notice>: MobileInstallationInstall: failed with -1
Aug 28 21:07:55 unknown installd[7066] <Error>: 00403000 install_application: Could not preflight application install
Aug 28 21:07:56 unknown installd[7066] <Error>: 00403000 handle_install: API failed
Aug 28 21:07:56 unknown installd[7066] <Error>: 00403000 send_message: failed to send mach message of 71 bytes: 10000003
Aug 28 21:07:56 unknown installd[7066] <Error>: 00403000 send_error: Could not send error response to client

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.

  1. I have verified that all my certificates are in order.  Deleted my mobile provisioning profiles manually, re-added them from the Apple developer portal.
  2. Open Disk Utility and do a full verify and repair disk permissions.
  3. 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.

 

, , , , , , , ,

2 Comments

Unity3D File Based Assetbundles on the iPhone

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.

In the project hierarchy, let’s go ahead and create a simple directory structure as follows:

/Example Project/
/Example Project/iphone/
/Example Project/iphone/objects/
/Example Project/iphone/materials/

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.

View Code CSHARP
using System;
using System.IO;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Object=UnityEngine.Object;
 
public class MPCreateAssetBundle : MonoBehaviour {
 
	private static String[] mpAssetDir = new String[]{"iphone", "ipad", "macosx", "pc"};// , "universal"}; <-- not needed, use the /Resources/ folder.
 
	[MenuItem("Custom/Monkey Prism/Create All Assetbundles #&i")]
	public static void Execute() {
		Debug.Log("Creating Assetbundles");
		bool blnFound = false;
		String currentDir = null;
		foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets)) {
			blnFound = true;
 
			if (o.name.Contains("@")) continue; //animations!
			String assetPath = AssetDatabase.GetAssetPath(o);
			if (!File.Exists(assetPath)) {
				currentDir = assetPath;
				continue; //Files only.
			}
			//Only check those directories that we have specified in the mpAssetDir
			Debug.Log(assetPath);
 
			String currentBuildType = null;
			foreach (String s in mpAssetDir) {
				if (assetPath.Contains("/"+s+"/")) {
					currentBuildType = s;
					break;
				}
			}
			if (currentBuildType == null) continue; //if the directory is not found to be one from the mpAssetDir bail out.
 
			string assetBundleName = null, genericName = null;
 
			List<Object> toinclude = new List<Object>();
 
			//Generate pre-fabs for everything in the finished pre-fab directory.
 
			if (o.GetType() == typeof(GameObject)) {
				Debug.Log("GameObject " + currentDir);
 
				String d = CharacterRoot((GameObject)o);
				d += "materials/";
				Debug.Log(d);
				List<Material> materials = CollectAll<Material>(d);
				Debug.Log("materials count=" + materials.Count);
 
				genericName = o.name.ToLower();
				assetBundleName = currentBuildType + "-prefab-" + genericName;
				//Package up the prefabs in the iPhone directory.
				toinclude.Add(o);
				//Do we need to add in a material?  I think so.
				foreach (Material m in materials) {
					Debug.Log("Material Name=" + m.name);
                    if (m.name.Contains(genericName)) {
						toinclude.Add(m);
						Debug.Log("Added a new material!");
					}
				} //end foreach
 
			} 
 
			if (assetBundleName == null) continue;
 
 
			// Create a directory to store the generated assetbundles.
            if (!Directory.Exists(AssetbundlePath))
                Directory.CreateDirectory(AssetbundlePath);
 
            // Delete existing assetbundles for current object
            string[] existingAssetbundles = Directory.GetFiles(AssetbundlePath);
            foreach (string bundle in existingAssetbundles) {
                if (bundle.EndsWith(".assetbundle") && bundle.Contains("/assetbundles/" + assetBundleName))
                    File.Delete(bundle);
            }
 
			//Directories expected.
			Debug.Log("currentBuildType = " + currentBuildType);
 
			//path = AssetbundlePath + bundleName + ".assetbundle";
			if (toinclude.Count > 0) {
				String path = AssetbundlePath + assetBundleName + ".assetbundle";
				Debug.Log(path);
				if (currentBuildType.Equals(mpAssetDir[0]) || currentBuildType.Equals(mpAssetDir[1])) //iPhone & iPad
					BuildPipeline.BuildAssetBundle(null, toinclude.ToArray(), path, BuildAssetBundleOptions.CollectDependencies, BuildTarget.iPhone);
				else //TODO: might need to condition further and might want to use an enum with the conditional.
					BuildPipeline.BuildAssetBundle(null, toinclude.ToArray(), path, BuildAssetBundleOptions.CollectDependencies);
			}
 
 
		} //end foreach
 
		if (!blnFound) {
			Debug.Log("no objects were found for building assets with.");	
		}
	}
 
	public static string AssetbundlePath
    {
        get { return "assetbundles" + Path.DirectorySeparatorChar; }
    }
 
	// This method loads all files at a certain path and
    // returns a list of specific assets.
    public static List<T> CollectAll<T>(string path) where T : Object
    {
        List<T> l = new List<T>();
        string[] files = Directory.GetFiles(path);
 
        foreach (string file in files)
        {
            if (file.Contains(".meta")) continue;
            T asset = (T) AssetDatabase.LoadAssetAtPath(file, typeof(T));
            if (asset == null) throw new Exception("Asset is not " + typeof(T) + ": " + file);
            l.Add(asset);
        }
        return l;
    }	
	// Returns the path to the directory that holds the specified FBX.
    static string CharacterRoot(GameObject character)
    {
        string root = AssetDatabase.GetAssetPath(character);
        return root.Substring(0, root.LastIndexOf('/') + 1);
    }
 
}

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:

View Code CSHARP
using System;
using UnityEngine;
using System.Collections;
 
public class Example : MonoBehaviour {
	private WWW www;
	private AssetBundleRequest gameObjectRequest;	
	// Use this for initialization
	IEnumerator Start () {
        //TODO: change the name of the file below!!!
		String strPath = "file://" + Application.dataPath + "/../assetbundles/iphone-prefab-box.assetbundle";
		Debug.Log(strPath);
		www = new WWW(strPath);
		yield return www;
        /* TODO: change the name "Box" to match the name of your prefab that you compiled into the assetbundle on step 1. */
		AssetBundleRequest request = www.assetBundle.LoadAsync("Box", typeof(GameObject));
		yield return request;
		Instantiate(request.asset, new Vector3(3f, 0f, 0f), Quaternion.identity);
		Instantiate(request.asset, new Vector3(0f, 0f, 0f), Quaternion.identity);
		Instantiate(request.asset, new Vector3(-3f, 0f, 0f), Quaternion.identity);
		www.assetBundle.Unload(true);
	}
        void Update() { }
}

NOTE: Make sure to change the TODO line in the code to match your file name! If you don’t do this, it might not work!

We’re nearly done! Drag your Example.cs script onto the GameObject you created earlier. Here is how my project looks:

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

, , , , , , ,

19 Comments

Cocos2D and Box2D Compilation Errors

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.
==========================
==========================
  1. Go to Project -> Edit Active Target “myCocos2DProject”
  2. 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.)
Happy Box2D coding.

, , , ,

1 Comment