Bug 46849 - Unable to build a valid .ipa using Mac Build Agent and linking to an external library
Summary: Unable to build a valid .ipa using Mac Build Agent and linking to an external...
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: MSBuild ()
Version: XI 10.4 (C9)
Hardware: PC Windows
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-11-12 09:52 UTC by Richard Urwin
Modified: 2017-01-30 13:47 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
installation / crash on startup log (29.12 KB, text/plain)
2016-12-20 17:16 UTC, Richard Urwin
Details
device crash log (47.77 KB, text/plain)
2016-12-20 17:20 UTC, Richard Urwin
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Richard Urwin 2016-11-12 09:52:25 UTC
Our iPhone app needs to link to libsqlcipher.a.

We therefore need to get a copy of it onto the Mac Build Agent.

The only way to do this appears to be to include the file in a project and specify ‘Build Action’ = ‘Copy Always’. The problem with this is that it then gets included in the .ipa which is forbidden by Apple.

As far as I can tell, this ultimately means that it is impossible to link to external libraries and build a valid .ipa using a Mac Build Agent (unless the file exists in library location on the Mac beforehand, which will cause issues with versioning).

Here’s the build error / location that the Mac Build Agent is looking in:

----------------------------------------

"E:\CCNet\Projects\NativeApps\iPhone\trunk\Source\Psonar.Apps\Psonar.Apps.iOS\Psonar.Apps.iOS.sln" (Build target) (1) ->
"E:\CCNet\Projects\NativeApps\iPhone\trunk\Source\Psonar.Apps\Psonar.Apps.iOS\Psonar.Apps.iOS.PayPerPlay\Psonar.Apps.iOS.PayPerPlay.csproj" (default target) (2) ->
(_CompileToNative target) -> 
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(700,3): error : Native linking error: file not found: /Users/xamarin/Library/Caches/Xamarin/mtbs/builds/Psonar.Apps.iOS.PayPerPlay/7cdd1df85a45ad5f48dd019c66ecc69b/libsqlcipher.a [E:\CCNet\Projects\NativeApps\iPhone\trunk\Source\Psonar.Apps\Psonar.Apps.iOS\Psonar.Apps.iOS.PayPerPlay\Psonar.Apps.iOS.PayPerPlay.csproj]
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(700,3): error : Native linking failed. Please review the build log and the user flags provided to gcc: -L/Users/xamarin/Library/Caches/Xamarin/mtbs/builds/Psonar.Apps.iOS.PayPerPlay/7cdd1df85a45ad5f48dd019c66ecc69b -L/usr/lib -licucore -lsqlcipher -force_load /Users/xamarin/Library/Caches/Xamarin/mtbs/builds/Psonar.Apps.iOS.PayPerPlay/7cdd1df85a45ad5f48dd019c66ecc69b/libsqlcipher.a [E:\CCNet\Projects\NativeApps\iPhone\trunk\Source\Psonar.Apps\Psonar.Apps.iOS\Psonar.Apps.iOS.PayPerPlay\Psonar.Apps.iOS.PayPerPlay.csproj]
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(700,3): error : Native linking failed. Please review the build log. [E:\CCNet\Projects\NativeApps\iPhone\trunk\Source\Psonar.Apps\Psonar.Apps.iOS\Psonar.Apps.iOS.PayPerPlay\Psonar.Apps.iOS.PayPerPlay.csproj]

----------------------------------------

We're building using MSBuild and CC.NET on Windows Server 2008 R2.
Comment 1 Jeffrey Stedfast 2016-11-14 18:47:09 UTC
What you need to do instead is to include libsqlcipher.a as a Native Reference. I'm not sure what the UI for Visual Studio is for this (I'm on a Mac), but in Xamarin Studio, it looks like this:

1. Right-click on the project
2. Move your mouse down to the "Add >" submenu
3. Select "Add Native Reference"

At this point a dialog pops up and allows you to select a file. Select the libsqlcipher.a file.

This will create a "Native References" folder in your Solution tree and add the "libsqlcipher" native library, resulting in a view like this:

http://screencast.com/t/txnxE3jE0j

If you right-click "libsqlcipher", you'll get a context menu that allows you to select "Properties" which you can use to specify all of the linker flags:

http://screencast.com/t/mkLaNxs3Dr2A


If Visual Studio doesn't have this functionality, then I'll move this over to the VS team to implement. The msbuild functionality is there, though, and this all works.
Comment 2 Alex Soto [MSFT] 2016-11-15 06:43:12 UTC
@Richad let us know if you were able to fix your issue :)
Comment 3 Richard Urwin 2016-11-15 14:40:52 UTC
Hi,

I think it fixed it - thanks!

I'm now working through other issues though. The current one is missing files:

(_CopyResourcesToBundle target) -> 
  C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(411,3): error : System.IO.FileNotFoundException: /Users/xamarin/Library/Caches/Xamarin/mtbs/builds/Psonar.Apps.iOS.PayPerPlay/7cdd1df85a45ad5f48dd019c66ecc69b/obj/iPhone/Production-Release-AppStore/optimized/Images/Menu/notificationIcon_empty@2x.png does not exist [E:\CCNet\Projects\NativeApps\iPhone\trunk\Source\Psonar.Apps\Psonar.Apps.iOS\Psonar.Apps.iOS.PayPerPlay\Psonar.Apps.iOS.PayPerPlay.csproj]

I think this might be related to the Build Action / Copy to Output Directory settings. We have some files as:

Build Action = Content
Copy to Output Directory = Do Not Copy

and some as:

Build Action = BundleResource
Copy to Output Directory = Do Not Copy

It seems to work when building in Xamarin Studio but not using MSBuild.

What's the difference? Should it matter what these settings are?

Thanks,
Richard
Comment 4 Timothy Risi 2016-12-19 19:43:35 UTC
Hi Richard,

Are you still seeing this issue?  And if so, could you provide a full build log for what's happening?
Comment 5 Richard Urwin 2016-12-20 09:33:51 UTC
Hi,

Jeffrey's solution worked and so the .ipa now builds, however it crashes during startup - we're having problems working out why.

It builds fine from Xamarin studio on a Mac though.

Comparing the .ipa files using Windiff doesn't shed any light on the situation - there are no files obviously missing, for example.

I'll attach build & device logs shortly.

Cheers,
Richard
Comment 6 Richard Urwin 2016-12-20 17:16:19 UTC
Created attachment 18942 [details]
installation / crash on startup log

When I build our app with CC.NET, the .ipa builds and appears to install successfully but then it crashes on startup.

Can you see anything in this log which might indicate what's going wrong?

Device: iPhone 5 (Model A1429)
OS version: 9.3.4 (13G35)

Thanks,
Rich
Comment 7 Richard Urwin 2016-12-20 17:20:13 UTC
Created attachment 18943 [details]
device crash log

Here's the device crash log too.
Comment 8 Vincent Dondain [MSFT] 2017-01-23 23:25:08 UTC
Hi Richard,

So let me recap:

1. The initial issue for this bug was: "Unable to build a valid .ipa using Mac Build Agent and linking to an external library".

Jeff gave the right answer by recommending to include the library as a Native Reference.

You said it solved the issue. Based on that this bug should be closed.

Note: when you have unrelated issues it's best to open a new bug and/or also ask on the forums where you might get an even quicker answer.

---

2. You seemed to have build issues based on notificationIcon_empty@2x.png but since comment 5 is about startup issue I assumed you fixed the build issues :P

---

3. So you gave us some startup logs, I can see an exception being thrown:

Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/41612C73-C2F8-44C1-8DD2-88E99F10044A/PsonarAppsiOSPayPerPlay.app> (loaded)' with name '

That can sometimes happen when files are corrupted, have been renamed and removing, adding them / recreating them might solve the issue. In your case you're having issues with one of your xib, now we don't have your solution (or a test case to be able to indicate exactly where/what the issue is). You might also want to check your csproj to see if your files have the right names.

---

Since this original bug is now fixed I'm gonna close it.

If you're still experiencing the issue rest assured we will help you find the answer but I will have to ask you to create a new bug for that including:

- Your XS/VS about information.
- All logs (build output, application output, device logs...).
- Potentially a test case or your original solution that you can send privately.

Thanks.
Comment 9 Richard Urwin 2017-01-30 13:47:37 UTC
Hi Vincent,

Apologies for the delay!

Taking your points in turn:

1 - OK!

2 - the build issue with 'notificationIcon_empty@2x.png' only occurs when we try to build the AppStore configuration. We can build our other configurations OK - I can't see why this file is only a problem in a specific configuration. Any ideas?

3 - i'll try deleting / re-adding

I'll create a new issue once I've addressed issues 1 - 3.

Thanks,
Richard