Bug 56690 - Latest Xamarin.Facebook (4.22 as opposed to 4.16.1) breaks ability to install multiple apps due to ${ApplicationID} not replacing properly
Summary: Latest Xamarin.Facebook (4.22 as opposed to 4.16.1) breaks ability to install...
Status: RESOLVED DUPLICATE of bug 51689
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 7.1 (C9)
Hardware: PC Windows
: --- normal
Target Milestone: 15.4
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2017-05-19 22:22 UTC by Craig Johnson
Modified: 2017-08-15 22:08 UTC (History)
4 users (show)

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

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 DUPLICATE of bug 51689

Description Craig Johnson 2017-05-19 22:22:48 UTC
Something recently has changed making it impossible to install more than 1 of our branded apps onto the same Android device.

The generic message from the package installer on the device was of no help.

So I attempted to install via the ADB shell (package name com.spot.mdc.devapix)

The first app installed fine as usual but then on the 2nd app it failed with the intriguing message below…

INSTALL_FAILED_CONFLICTING_PROVIDER: Package couldn't be installed in {path}: Can't install because provider name dollar_openBracket_applicationId_closeBracket (in package com.spot.mdc.devapiy) is already used by com.spot.mdc.devapix.

After investigation, it turns out the error is in the adoption of the most recent version of the Xamarin Facebook Android NuGet package (upgraded to 4.22 from 4.16.1).

Upon further investigation, it appears the only possible cause is that the file...

https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/main/AndroidManifest.xml

...being merged into my app's main AndroidManifest.xml contains a ${applicationId} token for which THE GRADLE BUILD SYSTEM PROPERLY performs a token substitution so as to disambiguate amongst all registered content providers. HOWEVER, the Xamarin toolchain (I am building from Visual Studio on Windows) resolves the token as "dollar_openBracket_applicationId_closeBracket".

This causes the SAME content provider insertion into however many apps we build, hence why when we try to install anything past the first app, the device complains that the provider is already in use and the world is borked.

Given that you appear to have a dependency on the Facebook SDK and whatever they supply, I only have two options: wait for Xamarin to support a proper token substitution in your own build process, or, crack open the resulting .APK from the build process and fix the errant line and then re-create the .APK.

I would rather not have to do this.

Thank you.
Comment 1 Ben Askren 2017-05-26 22:11:55 UTC
+1.  I have the same issue.
Comment 2 Ben Askren 2017-05-26 22:30:39 UTC
Looks like other's have tripped over this issue in other ways.

https://stackoverflow.com/questions/41551813/how-to-deal-with-applicationid-in-xamarin?answertab=active#tab-top

If they are correct, is there a way to apply the ManifestDocument.Save BEFORE manifest merge?
Comment 3 Ben Askren 2017-05-26 22:31:59 UTC
Looks like there is another bug report for this issue:  https://bugzilla.xamarin.com/show_bug.cgi?id=51689
Comment 4 Ben Askren 2017-05-26 22:37:36 UTC
... but that issue is for 3rd party packages.
Comment 5 Ben Askren 2017-05-27 14:25:44 UTC
Steps to reproduce:

(1) Using environment w/ VisualStudio Mac (see below for details)
(2) Select "File / New Solution ...".  "New Project" dialog box should appear.
(3) In the left pane, select "Multiplatform / App".
(4) In the middle pane, select "Blank Forms App".
(5) Select [Next] button.  The second "New Project" dialog should appear.
(6) Enter "DroidBuildFail" for "App Name:" and "Organization Identifier:".
(7) Assure that "Android" "Target Platform" has been selected.
(8) Select "Use Portable Class Library" for "Shared Code:" setting.
(9) Select [Next].  Third "New Project" dialog should appear.
(10) Select [Create].  VisualStudio will create a new project. Wait for packages to be added successfully.
(11) In the Solution Pad, right click on the "DroidBuildFail.Droid" project and select "Set as Startup Project".
(12) In the Solution Pad, expand the "DroidBuildFail.Droid" project and double click on the "Packages" folder.  The "Add Packages" dialog should appear.
(13) Search for and select the "Xamarin.Facebook.Android" package.
(14) Click [Add Package] and wait for the package to be successfully added.
(15) In the Solution Pad, right click on the ".Droid" project and select "Rebuild DroidBuildFail.Droid". 
(16) In the Solution Pad, right click on the  "DroidBuildFail" solution and select "Display Options / Show All Files".
(17) In the Solution Pad, navigate to "DroidBuildFail.Droid/obj/Debug/android" and select the "AndroidManifest.xml" file there.
(18) Inspect lines 34 and 46.  Notice the value of the "android:authorities" attribute is "dollar_openBracket_applicationId_closeBracket".  It should be your app's applicationId.

Environment Details:

=== Visual Studio Community 2017 for Mac ===

Version 7.0.1 (build 24)
Installation UUID: c3c61da2-4d87-4c39-b8d3-9fbf7e6af430
Runtime:
	Mono 5.0.1.1 (2017-02/5077205) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500010001

=== NuGet ===

Version: 4.0.0.2323

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
SDK: /usr/local/share/dotnet/sdk/1.0.3/Sdks
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.0.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

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

=== Apple Developer Tools ===

Xcode 8.3.2 (12175)
Build 8E2002

=== Xamarin.Mac ===

Version: 3.4.0.36 (Visual Studio Community)

=== Xamarin.Android ===

Version: 7.3.1.2 (Visual Studio Community)
Android SDK: /Users/ben/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.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		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)

SDK Tools Version: 26.0.2
SDK Platform Tools Version: 25.0.6
SDK Build Tools Version: 25.0.3

Java SDK: /usr
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.iOS ===

Version: 10.10.0.36 (Visual Studio Community)
Hash: d2270eec
Branch: d15-2
Build date: 2017-05-22 16:30:53-0400

=== Xamarin Inspector ===

Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

=== Build Information ===

Release ID: 700010024
Git revision: 7ab1ca2ced6f584e56b7a0d4d321d00775cd95c9
Build date: 2017-05-19 05:44:51-04
Xamarin addins: 08d17158f3365beee5e60f67999e607cce4b3f93
Build lane: monodevelop-lion-d15-2

=== Operating System ===

Mac OS X 10.12.5
Darwin 16.6.0 Darwin Kernel Version 16.6.0
    Fri Apr 14 16:21:16 PDT 2017
    root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
Comment 6 Ben Askren 2017-06-09 17:00:04 UTC
Is anyone assigned to this issue?
Comment 7 dean.ellis 2017-06-15 10:16:08 UTC
This should be fixed in the latest stable..

There is code in place to replace the "${applicationId}" during the save of the manifest document [1].

It uses the Package which we get from the AndroidManifest.xml in your project.


[1] https://github.com/xamarin/xamarin-android/blob/master/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs#L792
Comment 8 dean.ellis 2017-06-15 10:17:08 UTC
I will replicate here since I am working in that area at the moment.
Comment 9 dean.ellis 2017-06-15 13:47:13 UTC
ok, the issue is not in the way the app deals with the placeholder. The Manifest in the dll has the wrong value.
Comment 10 Craig Johnson 2017-07-13 19:53:16 UTC
Checking in - 30 days since last update. Is this confirmed fixed in the latest release?
Comment 11 dean.ellis 2017-07-14 10:51:15 UTC
Hi Craig, Confirmed means we have replicated the problem.

I have found where the issue is. It seems that the manifest file in the .aar aapt directory is the one that contains the "dollar_openBracket_applicationId_closeBracket" problem. Unfortunately this seems to be a result of the build process to build the .aar file. 

I am investigating a way to post process/fix up this issue since the building of these .aar files are outside of our control (they are produced by google, Facebook etc).
Comment 12 dean.ellis 2017-08-15 22:08:57 UTC
This and 51689 are exactly the same problem. Both are effected by this "dollar_openBracket_applicationId_closeBracket" which seems to be caused by gradle. We will cover the fix on 51689

*** This bug has been marked as a duplicate of bug 51689 ***