Esempio n. 1
0
        public void InstantRunNativeLibrary([Values("dx", "d8")] string dexTool)
        {
            if (!CommercialBuildAvailable)
            {
                Assert.Ignore("Not required on Open Source Builds");
            }

            if (!HasDevices)
            {
                Assert.Ignore("Test needs a device attached.");
                return;
            }
            var nativeLib = new AndroidItem.AndroidNativeLibrary("foo\\x86\\libtest.so")
            {
                BinaryContent  = () => new byte [10],
                MetadataValues = "Link=libs\\x86\\libtest.so",
            };
            var proj = new XamarinAndroidApplicationProject()
            {
                AndroidFastDeploymentType = "Assemblies:Dexes",
                UseLatestPlatformSdk      = true,
                DexTool         = dexTool,
                OtherBuildItems =
                {
                    nativeLib,
                },
            };

            proj.SetDefaultTargetDevice();
            using (var b = CreateApkBuilder(Path.Combine("temp", TestName))) {
                Assert.IsTrue(b.Install(proj), "install should have succeeded. 0");
                var logLines = b.LastBuildOutput;
                Assert.IsTrue(logLines.Any(l => l.Contains("Building target \"_BuildApkFastDev\" completely.") ||
                                           l.Contains("Target _BuildApkFastDev needs to be built")),
                              "Apk should have been built");
                Assert.IsTrue(logLines.Any(l => l.Contains("Building target \"_Upload\" completely")), "_Upload target should have run");
                Assert.IsTrue(logLines.Any(l => l.Contains("NotifySync CopyFile") && l.Contains("libtest.so")), "libtest.so should have been uploaded");

                nativeLib.BinaryContent = () => new byte [20];
                nativeLib.Timestamp     = DateTime.UtcNow.AddSeconds(1);
                Assert.IsTrue(b.Install(proj, doNotCleanupOnUpdate: true, saveProject: false), "install should have succeeded. 1");
                logLines = b.LastBuildOutput;
                Assert.IsFalse(logLines.Any(l => l.Contains("Building target \"_BuildApkFastDev\" completely.") ||
                                            l.Contains("Target _BuildApkFastDev needs to be built")),
                               "Apk should not have been built");
                Assert.IsTrue(logLines.Any(l => l.Contains("Building target \"_Upload\" completely")), "_Upload target should have run");
                Assert.IsTrue(logLines.Any(l => l.Contains("NotifySync CopyFile") && l.Contains("libtest.so")), "libtest.so should have been uploaded");
            }
        }
        public void InstantRunNativeLibrary([Values("dx", "d8")] string dexTool)
        {
            AssertDexToolSupported(dexTool);
            AssertCommercialBuild();
            AssertHasDevices();

            var nativeLib = new AndroidItem.AndroidNativeLibrary($"foo\\{DeviceAbi}\\libtest.so")
            {
                BinaryContent  = () => new byte [10],
                MetadataValues = $"Link=libs\\{DeviceAbi}\\libtest.so",
            };
            var proj = new XamarinAndroidApplicationProject()
            {
                AndroidFastDeploymentType = "Assemblies:Dexes",
                UseLatestPlatformSdk      = true,
                DexTool         = dexTool,
                OtherBuildItems =
                {
                    nativeLib,
                },
            };

            if (Builder.UseDotNet)
            {
                //NOTE: in .NET 6 by default an x86_64 emulator would fall back to x86 if we don't set this.
                proj.SetAndroidSupportedAbis(DeviceAbi);
            }
            proj.SetDefaultTargetDevice();
            using (var b = CreateApkBuilder(Path.Combine("temp", TestName))) {
                Assert.IsTrue(b.Install(proj), "install should have succeeded. 0");
                var logLines = b.LastBuildOutput;
                Assert.IsTrue(logLines.Any(l => l.Contains("Building target \"_BuildApkFastDev\" completely.") ||
                                           l.Contains("Target _BuildApkFastDev needs to be built")),
                              "Apk should have been built");
                Assert.IsTrue(logLines.Any(l => l.Contains("Building target \"_Upload\" completely")), "_Upload target should have run");
                Assert.IsTrue(logLines.Any(l => l.Contains("NotifySync CopyFile") && l.Contains("libtest.so")), "libtest.so should have been uploaded");

                nativeLib.BinaryContent = () => new byte [20];
                nativeLib.Timestamp     = DateTime.UtcNow.AddSeconds(1);
                Assert.IsTrue(b.Install(proj, doNotCleanupOnUpdate: true, saveProject: false), "install should have succeeded. 1");
                logLines = b.LastBuildOutput;
                Assert.IsFalse(logLines.Any(l => l.Contains("Building target \"_BuildApkFastDev\" completely.") ||
                                            l.Contains("Target _BuildApkFastDev needs to be built")),
                               "Apk should not have been built");
                Assert.IsTrue(logLines.Any(l => l.Contains("Building target \"_Upload\" completely")), "_Upload target should have run");
                Assert.IsTrue(logLines.Any(l => l.Contains("NotifySync CopyFile") && l.Contains("libtest.so")), "libtest.so should have been uploaded");
            }
        }