Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[One .NET] fix $(ApplicationId) and //manifest@package at the same time #6304

Merged

Conversation

jonathanpeppers
Copy link
Member

Fixes: #6302

If you try to use both $(ApplicationId) and @package in
AndroidManifest.xml at the same time, you hit errors during
deployment:

Xamarin.Android.Common.Debugging.targets(611,5): error XA0132: The package was not installed. Please check you do not have it installed under any other user.
If the package does show up on the device, try manually uninstalling it then try again.
You should be able to uninstall the app via the Settings app on the device.

From the spec, the AndroidManifest.xml is supposed to be preferred.

I found the <GetAndroidPackageName/> MSBuild task is accidentally
preferring the $(ApplicationId) MSBuild property. I reordered the
logic and only use the property when no value is found in the
AndroidManifest.xml.

I could reproduce the issue in a test, which now passes.

using var stream = File.OpenRead (ManifestFile);
using var reader = XmlReader.Create (stream);
if (reader.MoveToContent () == XmlNodeType.Element) {
var package = reader.GetAttribute ("package");
if (!string.IsNullOrEmpty (package)) {
package = ManifestDocument.ReplacePlaceholders (ManifestPlaceholders, package);
PackageName = AndroidAppManifest.CanonicalizePackageName (package);
} else if (!string.IsNullOrEmpty (PackageName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this else if here, and the "duplicate" PackageName = … statement between the two blocks, why not remove this else if, and turn the else if on line 64 into an if?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it around, should be better now. I removed a CanonicalizePackageName() call as well, so it isn't called twice.

Fixes: xamarin#6302

If you try to use both `$(ApplicationId)` and `@package` in
`AndroidManifest.xml` at the same time, you hit errors during
deployment:

    Xamarin.Android.Common.Debugging.targets(611,5): error XA0132: The package was not installed. Please check you do not have it installed under any other user.
    If the package does show up on the device, try manually uninstalling it then try again.
    You should be able to uninstall the app via the Settings app on the device.

From the spec, the `AndroidManifest.xml` is *supposed* to be preferred.

I found the `<GetAndroidPackageName/>` MSBuild task is accidentally
preferring the `$(ApplicationId)` MSBuild property. I reordered the
logic and only use the property when no value is found in the
`AndroidManifest.xml`.

I could reproduce the issue in a test, which now passes.
@jonpryor jonpryor merged commit 84d0d9b into xamarin:main Sep 22, 2021
jonpryor pushed a commit that referenced this pull request Sep 22, 2021
Fixes: #6302

If you try to use both the `$(ApplicationId)` MSBuild property and
the `/manifest/@package` attribute within `AndroidManifest.xml` at
the same time, you hit errors during deployment:

	Xamarin.Android.Common.Debugging.targets(611,5): error XA0132: The package was not installed. Please check you do not have it installed under any other user.
	If the package does show up on the device, try manually uninstalling it then try again.
	You should be able to uninstall the app via the Settings app on the device.

From the spec, the `AndroidManifest.xml` value is *supposed* to be
preferred.

I found that the `<GetAndroidPackageName/>` MSBuild task is
accidentally preferring the `$(ApplicationId)` MSBuild property.
I reordered the logic and only use the property when no value is
found in the `AndroidManifest.xml`.

I could reproduce the issue in a test, which now passes.
@jonathanpeppers jonathanpeppers deleted the applicationid-and-androidmanifest branch September 22, 2021 15:59
jonathanpeppers added a commit that referenced this pull request Sep 22, 2021
Fixes: #6302

If you try to use both the `$(ApplicationId)` MSBuild property and
the `/manifest/@package` attribute within `AndroidManifest.xml` at
the same time, you hit errors during deployment:

	Xamarin.Android.Common.Debugging.targets(611,5): error XA0132: The package was not installed. Please check you do not have it installed under any other user.
	If the package does show up on the device, try manually uninstalling it then try again.
	You should be able to uninstall the app via the Settings app on the device.

From the spec, the `AndroidManifest.xml` value is *supposed* to be
preferred.

I found that the `<GetAndroidPackageName/>` MSBuild task is
accidentally preferring the `$(ApplicationId)` MSBuild property.
I reordered the logic and only use the property when no value is
found in the `AndroidManifest.xml`.

I could reproduce the issue in a test, which now passes.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure to build/deploy/run with android:packageName and <ApplicationId>
3 participants