Bug 55483 - Latest stable Xamarin.Forms package causes Android build warnings
Summary: Latest stable Xamarin.Forms package causes Android build warnings
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-04-22 15:39 UTC by Edward Brey
Modified: 2017-04-25 20:03 UTC (History)
4 users (show)

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


Attachments
Build log (2.86 MB, text/plain)
2017-04-24 12:13 UTC, Edward Brey
Details
Build log with renamed project (2.85 MB, text/plain)
2017-04-24 13:25 UTC, Edward Brey
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 Edward Brey 2017-04-22 15:39:08 UTC
Environment:
* VS2017
* Xamarain.Android SDK 7.2.0.7
* JDK: 1.8.0_112 (latest installed via VS2017)
* Android NDK: r13b (latest installed via VS2017)
* Android SDK: 7.1 (latest installed via Android Studio)

Repro:
1. Create new project: Blank App (Android)
2. Install-Package Xamarin.Forms -DependencyVersion Highest
3. Build

The build results are very verbose. The includes this resource conflict warning:
c:\users\brey\Code\Sandbox\Android\Android\Resources\Resource.Designer.cs(29,78,29,102): warning CS0436: The type 'Resource' in 'c:\users\brey\Code\Sandbox\Android\Android\Resources\Resource.Designer.cs' conflicts with the imported type 'Resource' in 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'. Using the type defined in 'c:\users\brey\Code\Sandbox\Android\Android\Resources\Resource.Designer.cs'.

The results also include many of these warnings:
JAVAC : warning : unknown enum constant Scope.LIBRARY_GROUP
Comment 1 Edward Brey 2017-04-22 16:17:28 UTC
A related point of confusion is the comment on the troubleshooting page about locked versions:

https://developer.xamarin.com/guides/xamarin-forms/troubleshooting/
"each version of Xamarin.Forms is 'locked' to support only a specific version of the other packages"

This comment is inconsistent with the actual dependency constraints of Xamarin.Forms:
https://www.nuget.org/packages/Xamarin.Forms/2.3.4.224
MonoAndroid 7.0
Xamarin.Android.Support.Design (>= 23.3.0)
Xamarin.Android.Support.v4 (>= 23.3.0)
Xamarin.Android.Support.v7.AppCompat (>= 23.3.0)
Xamarin.Android.Support.v7.CardView (>= 23.3.0)
Xamarin.Android.Support.v7.MediaRouter (>= 23.3.0)

For MonoAndroid 7.0, the dependencies are ">=", which indicates the version is not locked. For MonoAndroid 1.0, the dependencies were locked, e.g. "Xamarin.Android.Support.Design (= 23.3.0)".
Comment 2 dean.ellis 2017-04-24 09:28:39 UTC
Edward, can you attach a diagnostic build log which contains all of the warnings please?
Comment 3 Edward Brey 2017-04-24 12:13:40 UTC
Created attachment 21725 [details]
Build log
Comment 4 Edward Brey 2017-04-24 12:16:35 UTC
I attached the build log. Am I supposed to change the bug status? I'm not sure, so I'm changing it back to NEW.
Comment 5 dean.ellis 2017-04-24 12:58:41 UTC
Edward. Looking at the build output it looks like you named your project "Android". Because we have a ton of Android namespaces we would recommend you avoid using the name Android if possible. As it will cause conflicts. 

So there is a class called Android.Resource in the Mono.Android dll. But because you called your project Android. you will also get a Android.Resource in the main assembly because that is what the Resource designer generates. 

You will find if you use a different project name that particular warning will go away. I personally use Foo.Droid, Foo.iOS etc for my project names as it makes sure you don't get any conflicts.
Comment 6 Edward Brey 2017-04-24 13:25:24 UTC
Created attachment 21731 [details]
Build log with renamed project

Thanks. Creating a new test project with a different name resolved the CS0436 conflict warning. There are still many of these warnings:
JAVAC : warning : unknown enum constant Scope.LIBRARY_GROUP 

The attachment BuildLog2.txt contains the build log using a project with a name other than Android. These JAVAC warnings also show up in my real-world project. What is the significance of them?
Comment 7 Jimmy [MSFT] 2017-04-24 18:38:01 UTC
The  Scope.LIBRARY_GROUP warnings are the same as bug 52944. 

Please try adding the Xamarin.Android.Support.Annotations package to your project and let us know if it helps. Thanks!

https://www.nuget.org/packages/Xamarin.Android.Support.Annotations/
Comment 8 Edward Brey 2017-04-25 13:49:07 UTC
Adding the beta Xamarin.Android.Support.Annotations package looks to be a good workaround until a fixed version is released. Thanks.

What about the discrepancy between the troubleshooting documentation and the package dependency spec I asked about in Comment 1? Which one is right, and which is wrong, or is there something I'm misunderstanding? Should this doc vs. code issue be tracked separately in Bugzilla?
Comment 9 Jimmy [MSFT] 2017-04-25 16:44:10 UTC
I'm glad to hear that it helped! This was actually an issue on the support packages side and the Xamarin.Android.Support.Annotations package was created as the fix. Since this is not an issue with the Forms package itself and you are no longer seeing the warnings, I will go ahead and resolve the report.

Regarding the out of date information in the troubleshooting doc, I've submitted a pull request to our documentation repo with an update to it. Unfortunately this repo is private, but I'm hoping the changes get merged and are visible in the next couple of days. Thank you for pointing this out!
Comment 10 Edward Brey 2017-04-25 16:47:31 UTC
Thanks. If I understand correctly, when the next stable version of the support packages is released, I should be able to remove the Xamarin.Android.Support.Annotations package. Is that correct?
Comment 11 Jimmy [MSFT] 2017-04-25 19:45:12 UTC
No, because the Xamarin.Android.Support.Annotations package _is_ the fix. The issue seems to be related to the Android support Java libraries themselves (we just provided C# bindings for them) and it is causing javac to throw those errors if the library is not included. Unless there is a change in the support libraries from Google which makes the package unnecessary, you will need to keep it added in your project.
Comment 12 Edward Brey 2017-04-25 20:03:39 UTC
If I create a new blank Android project, and I preview the changes for installing the latest pre-release Xamarin.Forms package, the list of packages to be installed doesn't include Xamarin.Android.Support.Annotations. It looks like Xamarin.Android.Support.Annotations is missing as a dependency on Xamarin.Forms or one of the packages it depends on.