Bug 34762 - Library AssetCatalogs conflict with App AssetCatalogs (can't have both)
Summary: Library AssetCatalogs conflict with App AssetCatalogs (can't have both)
Alias: None
Product: iOS
Classification: Xamarin
Component: MSBuild ()
Version: XI 9.0 (iOS9)
Hardware: PC Mac OS
: Low enhancement
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
Depends on:
Reported: 2015-10-12 11:20 UTC by John Miller [MSFT]
Modified: 2017-12-18 15:06 UTC (History)
17 users (show)

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

Test Case (27.50 KB, application/zip)
2015-10-12 11:20 UTC, John Miller [MSFT]
library-info-plist.patch (1.97 KB, patch)
2015-11-19 16:41 UTC, Jeffrey Stedfast

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 for Bug 34762 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description John Miller [MSFT] 2015-10-12 11:20:55 UTC
Created attachment 13281 [details]
Test Case


   With the latest tooling and SDK updates for iOS 9, ImageSet images are not loading with UIImage.FromBundle when the ImageSets are in a referenced iOS library project. 

Related* None of the ImageSet images seem to load when running on < iOS 9 simulators, like the iOS 8.4 simulator. 

**Steps to Reproduce:**

For iOS 9:
   1. Run the attached project on an iOS 9 simulator. 

For iOS 8.X
   1. Rebuild (clean) the project first. 
   2. Run the attached project on an iOS 8.4 simulator. 

**Actual Results:**

   There are two log messages in the Application Output to show the results of loading the images from the Image Sets. 
On iOS 9:

The "Compass" image loads successfully. This is packaged in the app. The "Pin" image does not load, which is in the referenced library. 
You should see a similar log to this:

> Compass: <UIImage: 0x79e741e0> size {22.666666, 22.666666} orientation 0 scale 3.000000

However, the "Pin" log shows it was NULL:

> Pin:     NULL

On iOS 8.X

Both images fail to load with a NULL log and also there are logs for this: 

> -[CUIThemeRendition newImageFromCSIDataSlice:ofBitmap: usingColorspace:] Unsupported pixel format in CSI got 4
> Unable to create unsliced image from csi bitmap data.

**Expected Results:**

   The images should load on iOS 8 and 9.

**Build Date & Platform:**

   === Xamarin Studio ===

Version 5.9.7 (build 22)
Installation UUID: e01c3049-a2d2-4e0a-aad8-afe6fb627c4d
	Mono 4.0.4 ((detached/d481017)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400040004

=== Apple Developer Tools ===

Xcode 7.0 (8227)
Build 7A220

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 1d27ac2
Branch: master
Build date: 2015-09-25 18:08:44-0400

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/johnmiller/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
Java SDK: /usr
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509070022
Git revision: 6bd1f169df44ca96addf8a035316c535a4fa46fa
Build date: 2015-09-30 12:30:15-04
Xamarin addins: 1c3e5c0859bdfec0ecd481a57ad6c03bc22f5536

=== Operating System ===

Mac OS X 10.10.5
Comment 1 Jeffrey Stedfast 2015-10-12 15:51:05 UTC
The problem is that the Library project's assets get compiled into an Assets.car file and the App project's assets overwrite that.

The only way to make this work is to somehow merge the assets from the Library into those in the main App project, but there's no tooling to allow us to do that, so for now... this is impossible.

I would recommend moving all Library assets into the main App project.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2015-10-13 05:46:44 UTC
@jeff, can we detect this at build time and show a warning/error instead of failing at runtime?
Comment 3 Isaias Bartelborth 2015-10-13 08:15:04 UTC
On stackoverflow.com is a recent question regarding "el capitan" with a similar problem, maybe this is a problem which arises from the xcode update.
Comment 4 Jeffrey Stedfast 2015-10-13 16:54:43 UTC
@rolf yea, we could certainly print an error in this case instead of silently breaking
Comment 5 Isaias Bartelborth 2015-10-16 05:11:08 UTC
@Jeffrey and @Rolf, the error message would be a useful and quality assuring option, but i am curious why it suddenly broke?

@Jeffrey how can it be that it was possible to let the app load images from the library projects previously and now it is impossible? Is there a breaking change on an obligatory dependency in the Apple tool chain or is this a breaking change in the Xamarin toolchain?

For now our company will stick with the copy-paste workaround, thus copying the assets from the library projects into all dependant app projects.
Comment 6 Jeffrey Stedfast 2015-10-20 16:13:41 UTC
Isaias, Apple's actool probably outputted individual images in a previous version and now outputs a single Assets.car file, thus clashing with the main app's Assets.car.
Comment 7 gdunko 2015-11-02 07:55:16 UTC

1) This is a significant bug for us because asset catalogs are no longer really if you want to write adaptive UI.   Some of the presentation logic now expects to find assets this way.  The collision of adaptive UI and writing reusable (library) UI components is causing a headache.

2) Ideally it would be great if we could expose (uncompiled) asset catalogs in iOS library projects through a NuGet package.   This would depend on them being put in the right place and flagging them as the right type of resource.  Then the compilation of the app project could include all asset catalogs into the final Assets.car.   P.S. Bringing .nib files across a nuget package has similar issues.
Comment 8 gdunko 2015-11-02 08:00:53 UTC
No longer really *optional*.  The word in quotes was removed from the comment.
Comment 9 Danil Kurkin 2015-11-11 06:14:23 UTC
Referring to the issue -

On test project created ImageSet with vector file(in PDF).

Imageview "Image" option doesn't see ImageSet as resource -
cannot be selected.

Other *.png's could be selected not a problem.
Comment 10 Jeffrey Stedfast 2015-11-19 13:20:03 UTC
If someone has reverse-engineered Apple's Assets.car file format, maybe we can figure out a way of merging them.
Comment 11 Jeffrey Stedfast 2015-11-19 16:41:21 UTC
Created attachment 13902 [details]

I have another idea...

I recently wrote a patch (attached) allowing developers to specify an Info.plist for their Library projects which could contain a MinimumOSVersion property which is used in the actool command-line (as well as ibtool, etc).

If you set the MinimumOSVersion to 7.0 or something low(er?), then actool should output individual files instead of an Assets.car file, allowing it to Work As Expected(tm) when referenced from a main app project.

You just need to patch your /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets file and then create an Info.plist and set a low MinimumOSVersion value.
Comment 12 Alek Slater 2016-05-16 12:08:51 UTC
Is this patch live, or do we still need to do this?

Is there any other workarounds for it? 

I'm using the same resources in 4 projects, so adding it to each of the app projects is  too much work (I'd have to add and remove from 4 projects every time I add / remove a new image). 

Just for the record, it loads completely fine on iOS 9 sims and devices, I've just noticed its totally broken on iOS 8 sims (dont have a device to try it on sorry).

How come it works ok on iOS 9, but not on iOS 8?
Comment 13 Jeffrey Stedfast 2016-06-06 18:25:47 UTC
Hey Alek,

I somehow missed your question until now. Sorry for the delayed response.

Yes, my patch went live.

As far as why it works on iOS9 and not on iOS8, that's a good question. I don't know :(
Comment 14 Tomasz Cielecki 2016-08-17 14:53:32 UTC
I have the same issue with one of my libraries (https://github.com/Cheesebaron/Chafu). When built on AppVeyor, which is running on a Windows Environment and the resulting NuGet containing the built dll's is used on either a Mac or Windows environment, the assets don't seem to work.

When the library an the app consuming it are both build on a Mac it seems to work fine.
Would be really great if this got addressed, soon-ish.
Comment 15 Tomasz Cielecki 2016-08-17 15:09:04 UTC
As for reverse engineering Assets.car, there seems to be a project, which at least can extract resources from it here: https://github.com/Marxon13/iOS-Asset-Extractor

This could make it possible to take all Assets.car files from every project, extract all ImageSets etc. and then make a new Assets.car file, no?
Comment 16 Vincent Dondain [MSFT] 2016-08-22 17:27:57 UTC
This is a valid bug but the task behind it is fairly huge so I'm marking it as CONFIRMED with a target milestone to be determined.
Comment 17 Jeffrey Stedfast 2016-11-30 20:58:41 UTC
This will require rearchitecting the way we carry resources over from library projects into the main app bundle which will unfortunately not be a trivial undertaking :(
Comment 18 Jon Goldberger [MSFT] 2017-10-05 19:28:22 UTC
As per comment 1 I was able to make having an asset catalog in the library as well as the app project work by adding an info.plist file to the library project and setting the deployment target to 6.x
Comment 19 Jon Goldberger [MSFT] 2017-10-05 19:28:40 UTC
Edit: "as per comment 11..."