Skip to content

Commit

Permalink
Add Unit Test for testOnly apps (dotnet#7637)
Browse files Browse the repository at this point in the history
Fixes: dotnet/maui#11345

For context users can mark their package as "testOnly" in the `AndroidManifest.xml`. When they do this `adb` also needs an additonal flag to install the package. 

PR xamarin/monodroid#1279 adds the ability to pass this additional flag to `adb`. 
This PR adds the ability to read the flag from the `AndroidManifest.xml`, so it can be used by other tasks. 
A unit test has also been added to the Device tests to make sure we can install `testOnly` packages.
  • Loading branch information
dellis1972 committed Feb 22, 2023
1 parent 618bd4a commit 41748e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/ReadAndroidManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class ReadAndroidManifest : AndroidTask
[Output]
public bool UseEmbeddedDex { get; set; } = false;

[Output]
public bool IsTestOnly { get; set; } = false;

public override bool RunTask ()
{
var androidNs = AndroidAppManifest.AndroidXNamespace;
Expand All @@ -52,6 +55,11 @@ public override bool RunTask ()
UseEmbeddedDex = value;
}

text = app.Attribute (androidNs + "testOnly")?.Value;
if (bool.TryParse (text, out value)) {
IsTestOnly = value;
}

var libraries = new List<ITaskItem> ();
foreach (var uses_library in app.Elements ("uses-library")) {
var attribute = uses_library.Attribute (androidNs + "name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,7 @@ because xbuild doesn't support framework reference assemblies.
<Output TaskParameter="EmbeddedDSOsEnabled" PropertyName="_EmbeddedDSOsEnabled" />
<Output TaskParameter="UsesLibraries" ItemName="AndroidExternalJavaLibrary" />
<Output TaskParameter="UseEmbeddedDex" PropertyName="_UseEmbeddedDex" />
<Output TaskParameter="IsTestOnly" PropertyName="_AndroidIsTestOnlyPackage" />
</ReadAndroidManifest>
<PropertyGroup>
<AndroidStoreUncompressedFileExtensions Condition=" '$(_EmbeddedDSOsEnabled)' == 'True' ">.so;$(AndroidStoreUncompressedFileExtensions)</AndroidStoreUncompressedFileExtensions>
Expand Down
4 changes: 3 additions & 1 deletion tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,14 @@ public void ResourceDesignerWithNuGetReference ([Values ("net8.0-android33.0")]
}

[Test]
public void SingleProject_ApplicationId ()
public void SingleProject_ApplicationId ([Values (false, true)] bool testOnly)
{
AssertHasDevices ();

proj = new XamarinAndroidApplicationProject ();
proj.SetProperty ("ApplicationId", "com.i.should.get.overridden.by.the.manifest");
if (testOnly)
proj.AndroidManifest = proj.AndroidManifest.Replace ("<application", "<application android:testOnly=\"true\"");

var abis = new string [] { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" };
proj.SetAndroidSupportedAbis (abis);
Expand Down

0 comments on commit 41748e1

Please sign in to comment.