Sunday, July 17, 2016

A fun build trist: Xamarin.iOS, a provisioning profile, and a certificate

A [sarcasm]fun[/sarcasm] problem to have:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets : error: No installed provisioning profiles match the installed iOS signing identities.

I use Bitrise for my mobile CI.  While its a great system, sometimes opaque errors can increase your blood pressure.  Honestly, its not any fault of Bitirse, its more a Xamarin problem in general and the maturity of the tool-sets.

For my error I had created my Apple certificate and provisioning profile in the Apple Developer portal with no issues.  I always download and install the certificate (a development certificate in my case) onto my Mac's Keychain.

For Bitrise you need to export the p12 file for the certificate and upload into Bitrise:
Here you can see I've uploaded both the certificate and the provisioning profile and I've saved the password. All good so far.

After still getting the error from Bitrise:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets : error: No installed provisioning profiles match the installed iOS signing identities.

I forced the selection of the correct certificate in the iOS project properties:

Still no luck.

Next I decided to explicitly set the provisioning profile so it's not using "magic" to determine which profile to use.

Visual Studio doesn't seem to understand or recognise the list of valid provisioning profiles however, as for me, the drop down list is blank.  Nevermind, it can be set in the XML.
First get the provisioning profile ID from your provisoning profile file. Its a file with the extension .mobileprovision, that you download from the Apple Developer portal.  Find a section in the XML that has a key "UUID".  Next to it is the Provisioning Profile ID. Copy this value.
        <key>UUID</key>
<string>19000000-aaaa-bbbb-cccc-ddddeeeeffff</string>

Paste the value into your Xamarin.iOS project csproj file.  You'll need to know which build configuration it will be building on the CI server.  For me its, Ad-Hoc/iPhone

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">
    <DebugType>none</DebugType>
    <Optimize>True</Optimize>
    <OutputPath>bin\iPhone\Ad-Hoc</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>False</ConsolePause>
    <MtouchArch>ARMv7, ARM64</MtouchArch>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <BuildIpa>True</BuildIpa>
    <CodesignProvision>19000000-aaaa-bbbb-cccc-ddddeeeeffff</CodesignProvision>
    <CodesignKey>iPhone Developer: Ben Rees (XABCDEFGHI)</CodesignKey>
  </PropertyGroup>

Paste the value into the CodesignProvision element.  This will force the Xamarin Builder to go looking for that exact provisioning profile.

But still no luck.  
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets : error: No installed provisioning profiles match the installed iOS signing identities.

I also turned on some extra debugging in Bitrise and found this:
/Users/vagrant/git/iOS/Info.plist : error: Project bundle identifier 'biz.rees.CorporateBs' does not match specified provisioning profile '19000000-aaaa-bbbb-cccc-ddddeeeeffff'

AHA!  The Bundle App ID must be case sensitive!  In the Apple Developer Portal I specified it as 
biz.rees.CorporateBS

Problem solved.

Icon Design and Tooling

I have to give a shout out to Inkscape what a fantastic tool for drawing and editing vector based icons (such as SVG files).  Thoroughly recommend it.  Its free and open source!

If it isn't suitable or you're looking for a cost effective way of producing professional icons or UI design check out https://www.fiverr.com/.  Its a market place to find, connect with, and hire services of just about any kind.

While you're waiting for your designer to draw your new icons, you can hire someone to pop balloons for you, or take a bath in baked beans.

More Common Xamarin Forms Project problems

As a follow on from Resolving Common Issues Loading Xamarin Samples here are some other issues I seem to be commonly running into. These issues are not only referring to Xamarin samples, but to any Xamarin project.

Corrupt Xamarin-Android ZIP files

Another common problem seems to be with corrupt Xamarin-Android SDK zip files located here:
C:\Users\<Your Username>\AppData\Local\Xamarin\zips
You'll see an error message similar to "...zip file "C:\Users\<Your Username>\AppData\Local\Xamarin\zips\1FD832DCC1792D8ACA07FAC3259FC5A9.zip" is corrupt.

Deleting all the zip files in that folder will cause them to be downloaded again during the next build within Vs.  This will make the next build very slow for obvious reasons. Let it run its course, and resist the temptation to cancel it. It could take 20minutes or more. After they are downloaded and cached in that folder again, build speed will be back to normal.



Error "aapt.exe" exited with code -1073741819.

Another common symptom is build errors in the Android generated file Resource.cs file.
The following error will be generated if there are dashes "-" in any file in the Resource/Drawables folders.

Android SDK Updates

Generally if an error follows an Android SDK update it is most likely related to new build and SDK tools being used just installed/updated.  Like the above error the most likely symptom of this is errors from the generated file Resource.cs file in your Android project.
First try running a Clean build then a Rebuild.If that doesn't work the best bet might be to revert back to a previous version of the SDK Build tools. Also check forums.xamarin.com.


Error The "XamlCTask" task failed unexpectedly.

System.IO.FileNotFoundException: Could not load file or assembly 'Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.
File name: 'Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'
Resolved by Deleting the entire packages folder contents and allowing a build to restore all packages.

Saturday, June 18, 2016

CheckOut a Pull Request in Git


Set-Up your Local Git Config

Locate the section for your github remote in the .git/config file. It looks like this:
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:joyent/node.git
Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:joyent/node.git
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Use the Command Line to Checkout a Pull Request

Now fetch all the pull requests:
$ git fetch origin
From github.com:joyent/node
 * [new ref]         refs/pull/1000/head -> origin/pr/1000
 * [new ref]         refs/pull/1002/head -> origin/pr/1002
 * [new ref]         refs/pull/1004/head -> origin/pr/1004
 * [new ref]         refs/pull/1009/head -> origin/pr/1009
...
To check out a particular pull request:
$ git checkout pr/999
Branch pr/999 set up to track remote branch pr/999 from origin.
Switched to a new branch 'pr/999'

Use Source Tree to Checkout a Pull Request

First, fetch all the open Pull Requests:

Then, simply right click the appropriate Pull Request and select Checkout.

Done.