Bug 37327 - Opening Android project in IDE creates an extra <None Include="Properties\AndroidManifest.xml" /> even if already defined
Summary: Opening Android project in IDE creates an extra <None Include="Properties\And...
Status: NEEDINFO
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 7.1 (C9)
Hardware: PC Windows
: Normal normal
Target Milestone: master
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2015-12-29 18:01 UTC by Jon Douglas [MSFT]
Modified: 2017-07-10 11:23 UTC (History)
8 users (show)

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


Attachments
Reproduction (16.27 KB, application/x-zip-compressed)
2015-12-29 18:01 UTC, Jon Douglas [MSFT]
Details
Workaround Solution (8.06 KB, application/x-7z-compressed)
2016-12-29 19:27 UTC, Daniel Cazzulino
Details
Diagnostic log for second build not building new APK (584.14 KB, text/plain)
2016-12-29 19:27 UTC, Daniel Cazzulino
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 for Bug 37327 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:
Status:
NEEDINFO

Description Jon Douglas [MSFT] 2015-12-29 18:01:58 UTC
Created attachment 14411 [details]
Reproduction

*Description:

Given a <Choose> definition in which a different AndroidManifest.xml is needed for a different App Store:

  <Choose>
    <When Condition=" '$(AndroidAppStore)'=='GooglePlay' ">
      <ItemGroup>
        <None Include="Properties\AndroidManifest.xml" />
      </ItemGroup>
      <PropertyGroup>
        <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
      </PropertyGroup>
    </When>
    <When Condition=" '$(AndroidAppStore)'=='Amazon' ">
      <ItemGroup>
        <None Include="Properties\Amazon\AndroidManifest.xml" />
      </ItemGroup>
      <PropertyGroup>
        <AndroidManifest>Properties\Amazon\AndroidManifest.xml</AndroidManifest>
      </PropertyGroup>
    </When>
  </Choose>

Opening a Xamarin.Android project inside an IDE will then cause the following elements to be added:

  <ItemGroup>
    <None Include="Properties\AndroidManifest.xml" />
  </ItemGroup>

*Reproduction

1. Open the .csproj and look over the <Choose> clause
2. Open the .sln in an IDE(VS/XS)
3. This will alter the .csproj and add another ItemGroup to the .csproj:

  <ItemGroup>
    <None Include="Properties\AndroidManifest.xml" />
  </ItemGroup>

*Regression

It seems that the behavior of Pre Xamarin 4 builds did not have this behavior. Thus it is a possible regression in post Xamarin 4 builds.
Comment 1 Jon Douglas [MSFT] 2015-12-29 18:02:33 UTC
*Version Information

Microsoft Visual Studio Professional 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01038

Installed Version: Professional

Visual Basic 2015   00322-40000-00000-AA564
Microsoft Visual Basic 2015

Visual C# 2015   00322-40000-00000-AA564
Microsoft Visual C# 2015

Visual C++ 2015   00322-40000-00000-AA564
Microsoft Visual C++ 2015

Visual F# 2015   00322-40000-00000-AA564
Microsoft Visual F# 2015

Windows Phone SDK 8.0 - ENU   00322-40000-00000-AA564
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1 (Beta8)   14.1.11106.0
ASP.NET and Web Tools 2015.1 (Beta8)

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.30624.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.5
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

GitHub.VisualStudio   1.0
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

JetBrains ReSharper Ultimate 2015.1.3   Build 102.0.20150724.141603
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2015 JetBrains, Inc.

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

NuGet Package Manager   3.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.50616.0
Microsoft SQL Server Data Tools

TypeScript   1.7.4.0
TypeScript for Microsoft Visual Studio

Visual Studio Tools for Unity   2.1.0.0
Visual Studio Tools for Unity

Xamarin   4.0.0.1717 (1390b70)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   6.0.0.35 (d300845)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   9.3.99.33 (ea30b32)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 2 Jose Gallardo 2016-11-24 20:48:09 UTC
Moving back to NEW as there was no INFO required.
Comment 3 Daniel Cazzulino 2016-12-29 19:26:29 UTC
Hi Jon,

<Choose> has never been very well supported in VS itself, and I'd say it's generally discouraged. 

In your particular case, you don't really need to conditionally include the items, only conditionally set the $(AndroidManifest) property instead. This will also make for a much more pleasant editing experience inside VS. Just let both items live in the .csproj without conditions:

	<ItemGroup>
		<None Include="Properties\AndroidManifest.xml" />
		<None Include="Properties\Amazon\AndroidManifest.xml" />
	</ItemGroup>


Then you can add a property group at the bottom of the .csproj like so:

	<PropertyGroup>
		<AndroidAppStore Condition="'$(AndroidAppStore)' == ''">Google</AndroidAppStore>
		<OutputPath>bin\$(Configuration)\$(AndroidAppStore)</OutputPath>

		<AndroidManifest Condition="'$(AndroidAppStore)' != 'Amazon'">Properties\AndroidManifest.xml</AndroidManifest>
		<AndroidManifest Condition="'$(AndroidAppStore)' == 'Amazon'">Properties\Amazon\AndroidManifest.xml</AndroidManifest>
	</PropertyGroup>


Note I changed the OutputPath too so when you build, you get distinct folders for each target store.

My suggestion is to even place this in a separate [App].targets file alongside the .csproj and import that instead:

   ....
	<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
	<Import Project="App121.targets" />
</Project>

Then, you can even include the .targets in the .csproj as a None item, and that will allow you to tweak the build process without having to unload and reload the project constantly.


This approach will work just fine for clean builds or rebuilds. 

you can do:

msbuild /p:AndroidAppStore=Google /t:Rebuild;Package

and 

msbuild /p:AndroidAppStore=Amazon /t:Rebuild;Package

And get the two distinct APKs for each store using the respective manifest.

There is a minor issue in that creating the APK will not detect that you completely changed the AndroidManifest.xml in use and the output APK will not be generated, even if the target output APK doesns't exist (since it points to a different output folder when you build for, say, Amazon after building for Google). I'm attaching the repro project and a diagnostics log file for the Android team to look at and see if that can be fixed.

Thanks!
Comment 4 Daniel Cazzulino 2016-12-29 19:27:17 UTC
Created attachment 19033 [details]
Workaround Solution

Should allow XA team to build and detect why the build isn't triggering when building with a different /p:AndroidAppStore value.
Comment 5 Daniel Cazzulino 2016-12-29 19:27:50 UTC
Created attachment 19034 [details]
Diagnostic log for second build not building new APK
Comment 6 dean.ellis 2017-07-10 09:39:50 UTC
I have a feeling this is because the AndroidManifest.xml file in the Amazon folder has a modified date which is before the one in obj/Debug/android/ ..
Comment 7 dean.ellis 2017-07-10 11:23:47 UTC
@kzu I can't repo this on the latest. It seems to produce the issue in the test app. It produces the apk with the correct name in the Amazon directory.