Bug 25569 - Resources not copied into application bundle in Unified API project
Summary: Resources not copied into application bundle in Unified API project
Alias: None
Product: iOS
Classification: Xamarin
Component: MSBuild ()
Version: XI 8.6.0
Hardware: All All
: Normal normal
Target Milestone: 8.6.x (services rel)
Assignee: Jeffrey Stedfast
: 26015 26134 26137 ()
Depends on:
Reported: 2014-12-22 07:29 UTC by Leon
Modified: 2015-07-29 16:36 UTC (History)
17 users (show)

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

Diagnostic build log (301.17 KB, text/plain)
2014-12-22 07:30 UTC, Leon

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:

Description Leon 2014-12-22 07:29:56 UTC
When building a project for the new Unified API the resources that have their build action set to InterfaceDefinition, iTunesArtwork, ImageAsset or BundleResource  are not copied to the appplication bundle. This leads to application icons, localized strings, images and nib files not being able to be loaded at runtime.

Resources contained in referenced Xamarin Components (ex: the images in the BTProgressHud components) and plist files with build action None (ex: Info.plist) are copied fine and are present in the application bundle.

I attached a diagnostic build log of the project.

Xamarin Studio

Version 5.7 (build 660)
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

Apple Developer Tools

Xcode 6.1.1 (6611)
Build 6A2008a


Version: (Business Edition)
Hash: 2c57f4e
Build date: 2014-12-18 16:42:49-0500
Comment 1 Leon 2014-12-22 07:30:55 UTC
Created attachment 9164 [details]
Diagnostic build log
Comment 2 Akhilesh kumar 2014-12-31 06:41:47 UTC
I have tried to reproduce this issue at my end. To reproduce this issue I have followed below steps:

1. Created Unified iOS application
2. Added 4 images in Resources folder
3. Set their build action to InterfaceDefinition, iTunesArtwork, ImageAsset or
4. Build and Run the application

I am getting following observation:

Getting build error for image having  Build action to 'InterfaceDefinition': 
/Users/360_macmini/Projects/TestUnified/TestUnified/Resources/InterfaceDefinition.PNG: Error: The operation couldn’t be completed. (com.apple.InterfaceBuilder error 2001.) (TestUnified)

Then I have removed this image and again run the application, it run successfully. When I checked application bundle it does not contain image having build action 'ImageAsset' and 'iTunesArtwork', however image of build action 'BundleResource' is present in application bundle.

Screencast: http://screencast.com/t/t4c0qs1k
Build output: https://gist.github.com/AkhileshKumar01/b164cddc9edd57bd6925

As application bundle it does not contain image having build action 'ImageAsset' and 'iTunesArtwork', so I am confirming this issue.

Environment info:
=== Xamarin Studio ===

Version 5.7 (build 660)
Installation UUID: ff0c16c6-3c75-46d8-ac56-56c3b56e2c76
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 2c57f4e
Build date: 2014-12-18 16:42:49-0500

=== Build Information ===

Release ID: 507000660
Git revision: 6a74f9bdb90d9415b597064d815c9be38b401fee
Build date: 2014-12-18 00:38:00-05
Xamarin addins: 57be0f5e1433cb58b70ea9b52e9dc77ad791be40

=== Operating System ===

Mac OS X 10.10.1
Darwin Apples-iMac.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 3 Jeffrey Stedfast 2015-01-05 14:18:12 UTC
The following change to your Xamarin.iOS.Common.targets file should solve this issue:

--- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
+++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
@@ -217,7 +217,7 @@ Copyright (C) 2013-2014 Xamarin. All rights reserved.
        <!-- TODO: check for duplicate items -->
-       <Target Name="_CopyContentToBundle"
+       <Target Name="_CopyContentToBundle" DependsOnTargets="_CollectBundleResources"
                Inputs = "@(_BundleResourceWithLogicalName)"
                Outputs = "@(_BundleResourceWithLogicalName -> '$(_AppBundlePath)%(LogicalName)')" >

(i.e. just add the DependsOnTargets XML property/value)
Comment 4 Jeffrey Stedfast 2015-01-05 14:27:16 UTC
Akhilesh: you tested something completely unrelated. The original bug reporter is not mis-setting the BuildAction of his resources to InterfaceDefinition (which of course should be expected to fail).

This is fixed in git master, going to try and get it into 8.6.0 final but it's a bit last-minute, so might not make it in.
Comment 5 Mohit Kheterpal 2015-01-06 08:34:27 UTC

We are not sure about the steps to verify this issue. Could you please provide steps if possible, so that we can Verify/Close this issue ?

Comment 6 Jeffrey Stedfast 2015-01-06 09:51:30 UTC
You can't really test this. The problem is that msbuild tries to build multiple things in parallel.

In Leon's case it was trying to copy the bundle resources into the app bundle *before* it had collected the bundle resources.

On most machines, this does not happen. I could not reproduce the error on my machine, for example, so the odds of you guys being able to reproduce it are slim if it hasn't already happened to you, it probably won't.
Comment 8 Alan McGovern 2015-01-06 16:03:12 UTC
Leon, to make absolutely sure we've got this fixed correctly could you share the full project (sln, csproj, resources etc) so we can compile locally to replicate the issue?
Comment 9 Jeffrey Stedfast 2015-01-06 16:07:35 UTC
That would require an NDA.

All he needs to do is test that the patch works for him locally.
Comment 10 Leon 2015-01-07 03:56:08 UTC
Adding the DependsOnTargets="_CollectBundleResources" attribute in the Xamarin.iOS.Common.targets file did fix part of the issue. Images, nib files etc. are present in the app bundle now and can be loaded at runtime.

However, I'm still encountering two issues in the app of which I am not certain if they are related to the build process:

Issue 1. Whenever I try to initialize a custom cell with the following piece of code:
 var views = NSBundle.MainBundle.LoadNib("TTMainSideMenuCell",null,null);
 TTMainSideMenuCell cell = Runtime.GetNSObject(  views.ValueAt(0) ) as TTMainSideMenuCell;

I get the exception: Objective-C exception thrown.  Name: NSUnknownKeyException Reason: [<UITableViewCell 0x79bdddd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mainBadgeView

This piece of code worked fine before and updating the outlets in XCode still updates the designer file of the TTMainSideMenuCell class. 
For some reason the LoadNib method seems to be trying to hook up the outlets on the File's owner (which is null, as intended) instead of the TTMainSideMenuCell class as it did before.

I already tried cleaning/rebuilding the project and reset/re-add the outlets but to no avail.
Comment 11 Leon 2015-01-07 04:05:17 UTC
Issue 2: Some of the DLL's references in the project are not working properly. 

I'm importing the following DLL's:

    <Reference Include="JASidePanels">
    <Reference Include="SQLite.Net">
    <Reference Include="SQLite.Net.Platform.XamarinIOS.Unified">
    <Reference Include="Newtonsoft.Json">
    <Reference Include="TeeChart.iOS">
    <Reference Include="BTProgressHUD">

Most of these assemblies can be loaded at runtime and work fine except for the TeeChart.iOS.Unified one. 
The application will give the following exception whenever it is about to call a method or initialize a class that references this assembly at any point during their run.

Could not load file or assembly 'TeeChart.iOS, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies"

Also noteworthy is that the metadata dll's of all the other referenced asseblies are present in the application package, but the TeeChart.iOS.Unified metadata file is missing for some reason.

This issue seems more like a issue with the DLL itself rather than the entire build process, but considering the missing metadata file is resembling the missing resource issue it was worth noting.
Comment 12 Jeffrey Stedfast 2015-01-07 10:32:28 UTC
Issue #2 is a separate issue for sure as the logic that copies content into the bundle doesn't copy dll's into the bundle, other logic does that (and is not even part of the Xamain.iOS.*.targets logic).

I don't think it's related to missing .mdb files as that's only needed for debugging anyway. Like you said, it's probably something wrong with the dll, but perhaps Sebastien can look into it (you should file another bug report so that it is easier to track - otherwise it gets confusing as to why this bug report is open, who is supposed to be looking at it, etc).

Issue #1 could be a build error, I'm not sure. I thought the exception you are seeing only happened if the .nib file was missing in the bundle but if you say it is there, then I don't know what else it could be.

Could you double-check to make sure that this particular nib file is present in the app bundle?
Comment 13 Leon 2015-01-07 11:00:56 UTC
Alright, I will look into contacting the developer of the problem causing DLL for that particular issue.

I also managed to narrow down the custom cell issue a bit.
The app bundle does contain the TTMainSideMenuCell.nib file.
The exception only occurs when the custom cell contains custom classes.

Also just before the exception occurs the following errors appear in the output when loading the NIB:

Unknown class TTMainSideMenuCell in Interface Builder file.
Unknown class MKBadgeView in Interface Builder file.

These classes are both managed C# classes that should have been exposed to ObjC/IB because of their [Register("<ClassName>")] attribute on their .designer partial class.

This makes it seem like a seperate issue from the original build issues.
Comment 14 Jason Smith [MSFT] 2015-01-12 19:47:35 UTC
https://github.com/XLabs/Xamarin-Forms-Labs/tree/unified reliably reproduces this bug where the bundle resources do not get properly copied over.
Comment 16 Jon Goldberger [MSFT] 2015-01-12 20:01:39 UTC
Related bug report: https://bugzilla.xamarin.com/show_bug.cgi?id=25936
Comment 17 Jeffrey Stedfast 2015-01-13 16:22:40 UTC
Jason's issue was an incorrect .csproj file that included non-existent png files.

I think we can close this now.
Comment 18 tom.quist 2015-01-14 07:51:48 UTC
Really annoying issue which wasted half of my day. Would've been great if you had added this to "Known Issues" in your release notes.
Comment 19 Alan McGovern 2015-01-14 10:28:47 UTC
Should we make missing files be a build error?
Comment 20 Jeffrey Stedfast 2015-01-14 10:47:11 UTC
Yes, and it already is. That's how I discovered the problem with the XLabs project missing those image files.
Comment 21 Allan Ritchie 2015-01-20 10:11:09 UTC
Updating the targets file fixed the nib loading issue, but app icons and splash screens are still not being referenced from the asset catalogs.
Comment 22 Allan Ritchie 2015-01-20 10:25:08 UTC
Nevermind, clearing all bin/obj after fix and restarting xamarin studio fixed the issue.
Comment 23 Jeffrey Stedfast 2015-01-20 11:29:31 UTC
Glad the fix worked out for you!
Comment 24 Jeffrey Stedfast 2015-01-21 12:06:21 UTC
just back-ported this fix to the 8.6 branch
Comment 25 Jeffrey Stedfast 2015-01-21 14:32:56 UTC
*** Bug 26137 has been marked as a duplicate of this bug. ***
Comment 26 Jeffrey Stedfast 2015-01-21 14:33:12 UTC
*** Bug 26015 has been marked as a duplicate of this bug. ***
Comment 27 Jeffrey Stedfast 2015-01-21 16:40:35 UTC
*** Bug 26134 has been marked as a duplicate of this bug. ***
Comment 28 GouriKumari 2015-01-22 14:09:32 UTC
I verified bug 26137, a duplicate of this bug and the issue reported is fixed with Xamarin.iOS Please see comment  #7 of bug 26137 for complete results.

Based on comment #22 of bug 25569 and based on comment #7 of bug 26137, I am marking this bug as verified fixed.

Test Env:
Xamarin Studio
Version 5.7.1 (build 52)
Installation UUID: 5ed3a124-4b77-4c6f-beb9-c830fd815e2a
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

Apple Developer Tools
Xcode 6.1 (6602)
Build 6A1052c

Version: (Enterprise Edition)
Hash: 80971a6
Build date: 2015-01-21 17:42:51-0500
Comment 29 Michael Stonis 2015-03-09 11:03:35 UTC
I found that this resolves the issue in most cases, but if I have storyboards in nested folders, they still fail to resolve. 

For example, if I have my project configured so that Build > iOS Application > iPhone / iPod Deployment Info / "Menu/MyMenu", it will throw an exception that it was unable to find the storyboard file. If I move the storyboard to the root of the project and update my project's config file, it will run appropriately.
Comment 30 Jeffrey Stedfast 2015-03-09 12:13:34 UTC
Thanks Michael, I've just fixed that issue in git master. It will make it into 8.10 for sure and possibly 8.8
Comment 31 Alessandro 2015-07-29 16:36:28 UTC
I'm using 8.10 but I've the same error