Bug 60343 - No resource found that matches the given name
Summary: No resource found that matches the given name
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 8.0 (15.4)
Hardware: PC Windows
: --- normal
Target Milestone: 15.6
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2017-10-24 10:20 UTC by Daniel Vaughan
Modified: 2018-05-10 15:53 UTC (History)
11 users (show)

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


Attachments
Repro Solution (75.91 KB, application/x-zip-compressed)
2018-01-07 16:26 UTC, Daniel Vaughan
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 FIXED

Description Daniel Vaughan 2017-10-24 10:20:57 UTC
Since the last VS update (15.4.1) whenever I go to debug my Android app, I receive build errors for all of my resources; complaining of missing resources. For example:

error: Error: No resource found that matches the given name (at 'contentDescription' with value '@string/AppBar_Button_ShowAbout')	

I've tried turning of fast app deployment (which was of anyway since that hasn't worked for a while.

The workaround is to rebuild my app every time I wish to debug.

Visual Studio 15.4.1
Xamarin.Android 8.0.0.33
Comment 1 Jon Douglas [MSFT] 2017-10-24 16:09:11 UTC
(In reply to Daniel Vaughan from comment #0)
> Since the last VS update (15.4.1) whenever I go to debug my Android app, I
> receive build errors for all of my resources; complaining of missing
> resources. For example:
> 
> error: Error: No resource found that matches the given name (at
> 'contentDescription' with value '@string/AppBar_Button_ShowAbout')	
> 
> I've tried turning of fast app deployment (which was of anyway since that
> hasn't worked for a while.
> 
> The workaround is to rebuild my app every time I wish to debug.
> 
> Visual Studio 15.4.1
> Xamarin.Android 8.0.0.33

Hi Daniel and thank you for your report. Can you please provide the following items for us to further investigate? You can reference our Bug Writing process for details:

https://bugzilla.xamarin.com/page.cgi?id=bug-writing.html

1. Steps to reproduce
2. Actual Results
3. Expected Results
4. Diagnostic Build Output - https://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Diagnostic_MSBuild_Output

Thanks!
Comment 2 Eric Schmeck 2017-10-29 08:47:30 UTC
Same problem here. I think this happens, because the theme I use is located in the styles.xml in a portable project, not in the main application itself. 

I also have to rebuild every time the code changes, otherwise it would not compile, because the resource.designer.cs is incomplete and the styles from the portable project are missing. 

Sadly, I cannot provide you the steps to reproduce, nor a test project, because most of the times I don't get the error there.
Comment 3 Daniel Vaughan 2017-10-29 14:24:52 UTC
I've sent the MSBuild output to you, Jon, via email.

My projects are set up as follows:
There is a head 'launcher' Android app project (A) and a referenced Android class library project (B).
B has string resources that are referenced in layouts in A. For example, mainview.axml in A may contain 
<TextView
    android:text="@string/aStringFromB" />

If I make a code change to a class in B, a build error occurs stating that no resource named aStringFromB can be found in project A.

Rebuilding fixes it, but it's hurting productivity.

It happens every time for me for a large project. However, I have not been successful in creating a repro solution.
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2017-11-01 00:49:53 UTC
## Cross-referencing note for the Xamarin team

The following IDE-focused issue report looks like it might also match this symptom:
https://developercommunity.visualstudio.com/content/problem/137529/unable-to-find-resources-intermittently-when-build.html
Comment 5 Jon Douglas [MSFT] 2017-11-01 18:38:44 UTC
Hey Daniel,

Thank you for your previous email. I really appreciate you.

I believe this will be fixed in our upcoming 15.5 Preview 3 release based on the following pull request that was recently fixed:

https://github.com/xamarin/xamarin-android/pull/986

Specifically in the following commit:

https://github.com/xamarin/xamarin-android/pull/986/commits/6a7df4b88e77d16bf619e25cd6d6f49cbef10319

To put it short:

This fixes an `aapt` error that occurs because DesignTime builds did not have their own set of cache files. DesignTime builds now have their own set of cache files which do not conflict with the main build's cache files.

If you aren't familiar with design-time builds, you can read up on them here:

https://github.com/dotnet/project-system/blob/master/docs/design-time-builds.md#what-is-a-design-time-build

Based on the description of https://bugzilla.xamarin.com/show_bug.cgi?id=60343#c3 I believe this commit might fix your current problem. I'm leaving this bug in NEEDINFO until we can get confirmation from you once 15.5 Preview 3 releases. For an ideal date when 15.5 Preview 3 releases, you can guesstimate based on our "Release History"

https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.1/#Release_History
Comment 6 Daniel Vaughan 2017-11-01 20:00:25 UTC
Thanks for investigating, Jon. I'll let you know on this thread if the update resolves the issue.

Regards,
Daniel
Comment 7 Jon Douglas [MSFT] 2017-11-09 19:09:00 UTC
(In reply to Daniel Vaughan from comment #6)
> Thanks for investigating, Jon. I'll let you know on this thread if the
> update resolves the issue.
> 
> Regards,
> Daniel

I am marking this issue as RESOLVED FIXED based on my findings in https://bugzilla.xamarin.com/show_bug.cgi?id=60343#c5

If this still occurs locally, please feel free to REOPEN this issue.
Comment 8 Eric Schmeck 2017-12-11 11:08:19 UTC
For me this problem still occurs in version 15.5.1
Comment 9 Daniel Vaughan 2017-12-11 11:51:34 UTC
It also still occurs for me.
Comment 10 Jon Douglas [MSFT] 2017-12-11 18:11:43 UTC
Hi Daniel and Eric,

Can you ensure that your NuGet packages are properly restored? If any of you have a simple project that this is occuring on handy and can upload to this bug report, that would be very helpful. Based on these types of errors they typically stem from 1 thing:

AAPT failing

Which in turn can be caused by many things which a Diagnostic Build Output would help us investigate further as well.

https://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Diagnostic_MSBuild_Output

Setting to NEEDINFO until we can get further confirmation.
Comment 11 Daniel Vaughan 2017-12-14 20:00:35 UTC
Hi Jon,

I'm currently blocked by a new issue https://bugzilla.xamarin.com/show_bug.cgi?id=60992

As soon as I receive the 15.5.2 update and it resolves that issue, I'll get back to you on this one.

Regards,
Daniel
Comment 12 Jon Douglas [MSFT] 2017-12-14 20:15:14 UTC
(In reply to Daniel Vaughan from comment #11)
> Hi Jon,
> 
> I'm currently blocked by a new issue
> https://bugzilla.xamarin.com/show_bug.cgi?id=60992
> 
> As soon as I receive the 15.5.2 update and it resolves that issue, I'll get
> back to you on this one.
> 
> Regards,
> Daniel

Please keep discussion about other issues in their respective bugzilla. This issue pertains to "No resource found that matches the given name". Can you confirm based on my comments in https://bugzilla.xamarin.com/show_bug.cgi?id=60343#c10 ?

Thanks Daniel!
Comment 13 Daniel Vaughan 2017-12-16 12:07:03 UTC
Project now builds, Jon. I'm closing the issue. Thanks for your help.
Comment 14 Jon Douglas [MSFT] 2017-12-16 19:43:49 UTC
(In reply to Daniel Vaughan from comment #13)
> Project now builds, Jon. I'm closing the issue. Thanks for your help.

Thank you for following up!
Comment 15 Eric Schmeck 2017-12-20 07:26:32 UTC
(In reply to Daniel Vaughan from comment #13)
> Project now builds, Jon. I'm closing the issue. Thanks for your help.

Hi Daniel, what did you do to fix this issue? I still get this error.
Comment 16 Daniel Vaughan 2017-12-22 12:30:47 UTC
Looks like I was too early closing this issue. I'm seeing it again too. I'm prevented from properly testing this issue because of another issue I'm facing https://bugzilla.xamarin.com/show_bug.cgi?id=61073 
I'm going to re-open this issue.
Comment 17 Daniel Vaughan 2018-01-07 16:26:23 UTC
Created attachment 26072 [details]
Repro Solution

To reproduce the issue please perform the following steps:

1. Open the XamarinAndroidResourceNotFound.sln in the attached zip file. 

2. From within Visual Studio 2017 select Build/Rebuild Solution.

3. From within Visual Studio 2017 select Build/Transform All Templates. 

4. Start Debugging (Press F5)

A build error should appear stating that No resource found that matches the given name (at 'text' with value '@string/testString').

The build error doesn't go away until a full Rebuild is performed.

'testString' is a string defined in ClassLibrary1/Resources/values/String.xml

The ClassLibrary1 project is referenced by the XamarinAndroidResourceNotFound project.

The T4 template generates a bunch of randomly named classes.
Comment 18 Jon Douglas [MSFT] 2018-01-08 17:51:45 UTC
(In reply to Daniel Vaughan from comment #17)
> Created attachment 26072 [details]
> Repro Solution
> 
> To reproduce the issue please perform the following steps:
> 
> 1. Open the XamarinAndroidResourceNotFound.sln in the attached zip file. 
> 
> 2. From within Visual Studio 2017 select Build/Rebuild Solution.
> 
> 3. From within Visual Studio 2017 select Build/Transform All Templates. 
> 
> 4. Start Debugging (Press F5)
> 
> A build error should appear stating that No resource found that matches the
> given name (at 'text' with value '@string/testString').
> 
> The build error doesn't go away until a full Rebuild is performed.
> 
> 'testString' is a string defined in ClassLibrary1/Resources/values/String.xml
> 
> The ClassLibrary1 project is referenced by the
> XamarinAndroidResourceNotFound project.
> 
> The T4 template generates a bunch of randomly named classes.

I believe this issue is resolved in 15.6 as part of a regression clean up:

https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.1/#Managed_Resource_Parser

I can reproduce this issue on 15.5, but not on 15.6 and thus I would consider this potentially fixed. We have an upcoming Xamarin.Android build in 15.6 Preview 2 that you can try using to see if this resolves on your end as well. If you can clarify that point, we can look into backporting this into a 15.5 service release if there is still time. I am going to mark this "RESOLVED FIXED" for the time being.
Comment 19 Daniel Vaughan 2018-01-08 19:29:38 UTC
Thanks Jon. I will let you know how I go with the preview.
Comment 20 Daniel Vaughan 2018-01-09 12:09:51 UTC
Jon, just to let you know, I'm receiving the same build issue in 15.6.0 Preview 1.1. I take it that Preview 2 will be released sometime in the near future according to your release cadence. At which point I'll let you know if it's resolved.
Comment 21 Daniel Vaughan 2018-02-08 21:50:02 UTC
I'm still experiencing this issue in 15.6.0 Preview 3.0.
Comment 22 Eric Schmeck 2018-03-06 08:13:20 UTC
Same thing here. I updated to the latest stable version 15.6 today and the issue still exists.
Comment 23 dean.ellis 2018-03-06 10:22:27 UTC
This should be fixed by xamarin-android/master/3b2cce2 but that is probably not going to be released unit 15.7.

For this having problems you can add the following to the top of the app csproj (just below the <Project /> element).

	<ItemDefinitionGroup>
		<AndroidResource>
			<SubType>Designer</SubType>
			<Generator>MSBuild:UpdateGeneratedFiles</Generator>
		</AndroidResource>
	</ItemDefinitionGroup>

This ensures that the DesignTime Build gets correctly updated as the Resource files change.
Comment 24 Eric Schmeck 2018-03-06 14:48:37 UTC
Hi Dean, thanks for your reply. I added these lines in my app csproj, but it doesn't seem to change anything for me. I still get "No resource found that matches the given name".
Comment 25 Daniel Vaughan 2018-03-06 15:08:22 UTC
I added the specified element as the first child of the Project element in the .apk project. Making a change to the code in that project still causes the "No resource found that matches the given name..."
Comment 26 dean.ellis 2018-03-06 15:25:10 UTC
@Jon Douglas 

Are you able to repo this. I have not been able too even with the sample project provided. If so can you provide diagnostic output for the test sample attached?
Comment 27 David Hollowell 2018-03-14 20:18:49 UTC
@dean.ellis
Hi, Dean. I have a customer reporting the same issue. I have diagnostic build logs. Can you reach out to me? david.hollowell@ alias
Comment 28 David Kendall 2018-03-22 17:34:29 UTC
Hello. I'm not sure if I should raise an additional bug or comment here, but I'm getting a similar error with Visual Studio for Mac.

Like described in this thread, in the company I work for we have two android applications where the main application is referencing resources defined in a secondary android library. Both applications have issues building the android solution stating it can't find the resources.
Comment 29 David Hollowell 2018-04-05 18:04:05 UTC
Hi David,
Thanks for the details. Can you share the precise output from the build logs showing the error messages? For my case, we noticed that the Target Android version was set to a version different than the value specified for the option, "Compile using Android version: (Target Framework)" and the Android SDKs for the specified target Android version weren't installed.
Does this reproduce for if you set the Target Framework setting to compile latest and then step up the target android version to match the compile version?
Comment 30 David Hollowell 2018-04-05 18:04:55 UTC
Hi David,
Thanks for the details. Can you share the precise output from the build logs showing the error messages? For my case, we noticed that the Target Android version was set to a version different than the value specified for the option, "Compile using Android version: (Target Framework)" and the Android SDKs for the specified target Android version weren't installed.
Does this reproduce for if you set the Target Framework setting to compile latest and then step up the target android version to match the compile version?
Comment 31 Miguel de Icaza [MSFT] 2018-04-06 14:32:07 UTC
Please see #android for the binary log
Comment 33 dean.ellis 2018-04-06 15:26:11 UTC
This looks like a design time build issue. The `_BuildAdditionalResourcesCache` target is being skipped because it appears to be up to date. However the obj/Debug/resource.cache file has no additional paths in it. 

There was a bug where if the Design time build runs first it creates an empty resource.cache file, because _BuildAdditionalResourcesCache is NOT run as part of the design time build. This should be fixed by [1]. In that fix we gave the design time build its own cache files so they would not interfere with the main build files. This fix should already be in the d15-7 preview channel. If would be helpful to know if anyone running d15-7 is still having the issue?

To work around deleting just the obj/Debug/resource.cache file should allow it to be regenerated. 

[1] https://github.com/xamarin/xamarin-android/commit/e55d6557
Comment 34 Daniel Vaughan 2018-04-07 20:48:26 UTC
I've been unable to repro this with VS 15.7.0 Preview 2.0.
Looks like it's resolved.
Thank you.

David Hollowell, Eric Schmeck, or David Kendall, please acknowledge that the issue is resolved for you. Due to the occasional nature of this issue, I'll hold off a day or two before closing the bug.
Comment 35 Eric Schmeck 2018-04-19 12:01:08 UTC
VS 15.7.0 Preview 4.0 seems to be working for me, but now ReSharper shows an error "ambiguous reference" for each Android Resource I'm using in the code. I can clear the cache for ReSharper, but next time I build, the errors returns. So I think this issue isn't resolved completely yet or is it a todo for ReSharper?
Comment 36 Daniel Vaughan 2018-04-19 14:31:33 UTC
Thanks Eric. I'd say that's a Resharper issue.
Comment 37 Ben 2018-05-10 15:53:21 UTC
After updating to Visual Studio Community version 7.5, I have also started getting "ambiguous reference" for all of my Android Resource layouts.  I can still build/compile, but this error does not make sense.

I am not using Resharper, so it's not a Resharper issue.

Below are further details of my environment:
=== Visual Studio Community 2017 for Mac ===

Version 7.5 (build 1254)
Installation UUID: 53d271a3-f98b-4609-8b6e-d35987a7e847
Runtime:
	Mono 5.10.1.47 (2017-12/8eb8f7d5e74) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 4.4.0.36 (master / 0c7c49a6)

	Package version: 510010047

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.0.5
	2.0.0
SDK: /usr/local/share/dotnet/sdk/2.1.4/Sdks
SDK Versions:
	2.1.4
	2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.2
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 8.3.0.19 (Visual Studio Community)
Android SDK: /Users/bsumang/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		5.0 (API level 21)
		5.1 (API level 22)
		6.0 (API level 23)
		7.0 (API level 24)
		7.1 (API level 25)
		8.0 (API level 26)
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 27.0.1
SDK Build Tools Version: 26.0.2

Java SDK: /usr
Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java...
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)