Skip to content

Commit 41748e1

Browse files
authored
Add Unit Test for testOnly apps (#7637)
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.
1 parent 618bd4a commit 41748e1

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/ReadAndroidManifest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class ReadAndroidManifest : AndroidTask
3535
[Output]
3636
public bool UseEmbeddedDex { get; set; } = false;
3737

38+
[Output]
39+
public bool IsTestOnly { get; set; } = false;
40+
3841
public override bool RunTask ()
3942
{
4043
var androidNs = AndroidAppManifest.AndroidXNamespace;
@@ -52,6 +55,11 @@ public override bool RunTask ()
5255
UseEmbeddedDex = value;
5356
}
5457

58+
text = app.Attribute (androidNs + "testOnly")?.Value;
59+
if (bool.TryParse (text, out value)) {
60+
IsTestOnly = value;
61+
}
62+
5563
var libraries = new List<ITaskItem> ();
5664
foreach (var uses_library in app.Elements ("uses-library")) {
5765
var attribute = uses_library.Attribute (androidNs + "name");

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,7 @@ because xbuild doesn't support framework reference assemblies.
16411641
<Output TaskParameter="EmbeddedDSOsEnabled" PropertyName="_EmbeddedDSOsEnabled" />
16421642
<Output TaskParameter="UsesLibraries" ItemName="AndroidExternalJavaLibrary" />
16431643
<Output TaskParameter="UseEmbeddedDex" PropertyName="_UseEmbeddedDex" />
1644+
<Output TaskParameter="IsTestOnly" PropertyName="_AndroidIsTestOnlyPackage" />
16441645
</ReadAndroidManifest>
16451646
<PropertyGroup>
16461647
<AndroidStoreUncompressedFileExtensions Condition=" '$(_EmbeddedDSOsEnabled)' == 'True' ">.so;$(AndroidStoreUncompressedFileExtensions)</AndroidStoreUncompressedFileExtensions>

tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,14 @@ public void ResourceDesignerWithNuGetReference ([Values ("net8.0-android33.0")]
764764
}
765765

766766
[Test]
767-
public void SingleProject_ApplicationId ()
767+
public void SingleProject_ApplicationId ([Values (false, true)] bool testOnly)
768768
{
769769
AssertHasDevices ();
770770

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

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

0 commit comments

Comments
 (0)