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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidPackageName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ public class GetAndroidPackageName : AndroidTask

public override bool RunTask ()
{
if (!string.IsNullOrEmpty (PackageName)) {
PackageName = AndroidAppManifest.CanonicalizePackageName (PackageName);
} else if (!string.IsNullOrEmpty (ManifestFile) && File.Exists (ManifestFile)) {
if (!string.IsNullOrEmpty (ManifestFile) && File.Exists (ManifestFile)) {
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);
PackageName = ManifestDocument.ReplacePlaceholders (ManifestPlaceholders, package);
}
}
}

// If we don't have a manifest, default to using the assembly name
// If the assembly doesn't have a period in it, duplicate it so it does
if (string.IsNullOrEmpty (PackageName)) {
if (!string.IsNullOrEmpty (PackageName)) {
// PackageName may be passed in via $(ApplicationId) and missing from AndroidManifest.xml
PackageName = AndroidAppManifest.CanonicalizePackageName (PackageName);
} else {
// If we don't have a manifest, default to using the assembly name
// If the assembly doesn't have a period in it, duplicate it so it does
PackageName = AndroidAppManifest.CanonicalizePackageName (AssemblyName);
}

Expand Down
24 changes: 24 additions & 0 deletions tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,29 @@ public void RunWithInterpreterEnabled ([Values (false, true)] bool isRelease)
Assert.IsTrue (didStart, "Activity should have started.");
}

[Test]
public void SingleProject_ApplicationId ()
{
AssertHasDevices ();

proj = new XamarinAndroidApplicationProject ();
proj.SetProperty ("ApplicationId", "com.i.should.get.overridden.by.the.manifest");

var abis = new string [] { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" };
proj.SetAndroidSupportedAbis (abis);
builder = CreateApkBuilder ();
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");

if (Builder.UseDotNet)
Assert.True (builder.RunTarget (proj, "Run"), "Project should have run.");
else if (CommercialBuildAvailable)
Assert.True (builder.RunTarget (proj, "_Run"), "Project should have run.");
else
AdbStartActivity ($"{proj.PackageName}/{proj.JavaPackageName}.MainActivity");

var didStart = WaitForActivityToStart (proj.PackageName, "MainActivity",
Path.Combine (Root, builder.ProjectDirectory, "startup-logcat.log"));
Assert.IsTrue (didStart, "Activity should have started.");
}
}
}