public void InvalidAndroidResource([Values(true, false)] bool useAapt2)
        {
            var invalidXml = new AndroidItem.AndroidResource(@"Resources\values\ids.xml")
            {
                TextContent = () => "<?xml version=\"1.0\" encoding=\"utf-8\" ?><resources><item/></resources>"
            };

            var proj = new XamarinAndroidApplicationProject();

            proj.SetProperty("AndroidUseAapt2", useAapt2.ToString());
            using (var b = CreateApkBuilder(Path.Combine("temp", TestName))) {
                var projectFile = Path.Combine(Root, b.ProjectDirectory, proj.ProjectFilePath);
                b.ThrowOnBuildFailure = false;
                proj.OtherBuildItems.Add(invalidXml);
                Assert.IsFalse(b.Build(proj), "Build should *not* have succeeded.");

                b.ThrowOnBuildFailure = true;
                proj.OtherBuildItems.Remove(invalidXml);

                //HACK: for random test failure
                b.Save(proj, doNotCleanupOnUpdate: true);
                File.SetLastWriteTimeUtc(projectFile, DateTime.UtcNow.AddMinutes(1));

                Assert.IsTrue(b.Build(proj), "Build should have succeeded.");

                b.ThrowOnBuildFailure = false;
                proj.OtherBuildItems.Add(invalidXml);

                //HACK: for random test failure
                b.Save(proj, doNotCleanupOnUpdate: true);
                File.SetLastWriteTimeUtc(projectFile, DateTime.UtcNow.AddMinutes(1));

                Assert.IsFalse(b.Build(proj), "Build should *not* have succeeded.");
            }
        }
Exemple #2
0
        public void RepetiviteBuildUpdateSingleResource()
        {
            var proj = new XamarinAndroidApplicationProject();

            using (var b = CreateApkBuilder("temp/RepetiviteBuildUpdateSingleResource", cleanupAfterSuccessfulBuild: false)) {
                b.Verbosity = Microsoft.Build.Framework.LoggerVerbosity.Diagnostic;
                BuildItem image1, image2;
                using (var stream = typeof(XamarinAndroidCommonProject).Assembly.GetManifestResourceStream("Xamarin.ProjectTools.Resources.Base.Icon.png")) {
                    var image_data = new byte [stream.Length];
                    stream.Read(image_data, 0, (int)stream.Length);
                    image1 = new AndroidItem.AndroidResource("Resources\\drawable\\Image1.png")
                    {
                        BinaryContent = () => image_data
                    };
                    proj.AndroidResources.Add(image1);
                    image2 = new AndroidItem.AndroidResource("Resources\\drawable\\Image2.png")
                    {
                        BinaryContent = () => image_data
                    };
                    proj.AndroidResources.Add(image2);
                }
                b.ThrowOnBuildFailure = false;
                Assert.IsTrue(b.Build(proj), "First build was supposed to build without errors");
                var firstBuildTime = b.LastBuildTime;
                Assert.IsTrue(b.Build(proj), "Second build was supposed to build without errors");
                Assert.IsTrue(firstBuildTime > b.LastBuildTime, "Second build was supposed to be quicker than the first");
                Assert.IsTrue(
                    b.LastBuildOutput.Contains("Skipping target \"_GenerateAndroidResourceDir\" because"),
                    "The Target _GenerateAndroidResourceDir should have been skipped");
                Assert.IsTrue(
                    b.LastBuildOutput.Contains("Skipping target \"_CompileJava\" because"),
                    "The Target _CompileJava should have been skipped");
                image1.Timestamp = DateTime.UtcNow;
                var layout = proj.AndroidResources.First(x => x.Include() == "Resources\\layout\\Main.axml");
                layout.Timestamp = DateTime.UtcNow;
                Assert.IsTrue(b.Build(proj, doNotCleanupOnUpdate: true, saveProject: false), "Third build was supposed to build without errors");
                Assert.IsTrue(
                    b.LastBuildOutput.Contains("Target _GenerateAndroidResourceDir needs to be built as input file") ||
                    b.LastBuildOutput.Contains("Building target \"_GenerateAndroidResourceDir\" completely."),
                    "The Target _GenerateAndroidResourceDir should not have been skipped");
                Assert.IsTrue(
                    b.LastBuildOutput.Contains("Skipping target \"_CompileJava\" because"),
                    "The Target _CompileJava (2) should have been skipped");
                Assert.IsTrue(
                    b.LastBuildOutput.Contains("Target _CreateBaseApk needs to be built as input file") ||
                    b.LastBuildOutput.Contains("Building target \"_CreateBaseApk\" completely."),
                    "The Target _CreateBaseApk should not have been skipped");
            }
        }
Exemple #3
0
        public void InvalidAndroidResource([Values(true, false)] bool useAapt2)
        {
            var invalidXml = new AndroidItem.AndroidResource(@"Resources\values\ids.xml")
            {
                TextContent = () => "<?xml version=\"1.0\" encoding=\"utf-8\" ?><resources><item/></resources>"
            };

            var proj = new XamarinAndroidApplicationProject();

            proj.SetProperty("AndroidUseAapt2", useAapt2.ToString());
            using (var b = CreateApkBuilder(Path.Combine("temp", TestName))) {
                b.ThrowOnBuildFailure = false;

                proj.OtherBuildItems.Add(invalidXml);
                Assert.IsFalse(b.Build(proj), "Build should *not* have succeeded.");

                proj.OtherBuildItems.Remove(invalidXml);
                Assert.IsTrue(b.Build(proj), "Build should have succeeded.");

                proj.OtherBuildItems.Add(invalidXml);
                Assert.IsFalse(b.Build(proj), "Build should *not* have succeeded.");
            }
        }
Exemple #4
0
        public void MoveResource()
        {
            var       proj  = new XamarinAndroidApplicationProject();
            BuildItem image = null;

            using (var stream = typeof(XamarinAndroidCommonProject).Assembly.GetManifestResourceStream("Xamarin.ProjectTools.Resources.Base.Icon.png")) {
                var image_data = new byte [stream.Length];
                stream.Read(image_data, 0, (int)stream.Length);
                image = new AndroidItem.AndroidResource("Resources\\drawable\\Image.png")
                {
                    BinaryContent = () => image_data
                };
                proj.AndroidResources.Add(image);
            }
            using (var b = CreateApkBuilder("temp/MoveResource")) {
                Assert.IsTrue(b.Build(proj), "First build should have succeeded.");
                var oldpath = image.Include().Replace('\\', Path.DirectorySeparatorChar);
                image.Include   = () => "Resources/drawable/NewImage.png";
                image.Timestamp = DateTimeOffset.UtcNow.AddMinutes(1);
                Assert.IsTrue(b.Build(proj), "Second build should have succeeded.");
                Assert.IsFalse(File.Exists(Path.Combine(b.ProjectDirectory, oldpath)), "XamarinProject.UpdateProjectFiles() failed to delete file");
                Assert.IsFalse(b.LastBuildOutput.Contains("Skipping target \"_Sign\" because"), "incorrectly skipped some build");
            }
        }
Exemple #5
0
        public void Check9PatchFilesAreProcessed([Values(false, true)] bool explicitCrunch)
        {
            var projectPath = string.Format("temp/Check9PatchFilesAreProcessed_{0}", explicitCrunch.ToString());
            var libproj     = new XamarinAndroidLibraryProject()
            {
                ProjectName = "Library1"
            };

            using (var stream = typeof(XamarinAndroidCommonProject).Assembly.GetManifestResourceStream("Xamarin.ProjectTools.Resources.Base.Image.9.png")) {
                var image_data = new byte [stream.Length];
                stream.Read(image_data, 0, (int)stream.Length);
                var image2 = new AndroidItem.AndroidResource("Resources\\drawable\\Image2.9.png")
                {
                    BinaryContent = () => image_data
                };
                libproj.AndroidResources.Add(image2);
            }
            using (var libb = CreateDllBuilder(Path.Combine(projectPath, "Library1"))) {
                libb.Build(libproj);
                var proj = new XamarinAndroidApplicationProject();
                using (var stream = typeof(XamarinAndroidCommonProject).Assembly.GetManifestResourceStream("Xamarin.ProjectTools.Resources.Base.Image.9.png")) {
                    var image_data = new byte [stream.Length];
                    stream.Read(image_data, 0, (int)stream.Length);
                    var image1 = new AndroidItem.AndroidResource("Resources\\drawable\\Image1.9.png")
                    {
                        BinaryContent = () => image_data
                    };
                    proj.AndroidResources.Add(image1);
                }
                proj.References.Add(new BuildItem("ProjectReference", "..\\Library1\\Library1.csproj"));
                proj.Packages.Add(KnownPackages.AndroidSupportV4_21_0_3_0);
                proj.Packages.Add(KnownPackages.SupportV7AppCompat_21_0_3_0);
                proj.Packages.Add(KnownPackages.SupportV7MediaRouter_21_0_3_0);
                proj.Packages.Add(KnownPackages.GooglePlayServices_22_0_0_2);
                proj.AndroidExplicitCrunch = explicitCrunch;
                proj.SetProperty("TargetFrameworkVersion", "v5.0");
                proj.SetProperty(proj.DebugProperties, "JavaMaximumHeapSize", "1G");
                proj.SetProperty(proj.ReleaseProperties, "JavaMaximumHeapSize", "1G");
                using (var b = CreateApkBuilder(Path.Combine(projectPath, "Application1"), false, false)) {
                    b.Verbosity = LoggerVerbosity.Diagnostic;
                    Assert.IsTrue(b.Build(proj), "Build should have succeeded.");
                    var path = Path.Combine(Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android/bin/packaged_resources");
                    var data = ZipHelper.ReadFileFromZip(path, "res/drawable/image1.9.png");
                    Assert.IsNotNull(data, "image1.9.png should be in {0}android/bin/packaged_resources",
                                     proj.IntermediateOutputPath);
                    var png = PNGChecker.LoadFromBytes(data);
                    Assert.IsTrue(png.Is9Patch, "image1.9.png should have been processed into a 9 patch image.");
                    data = ZipHelper.ReadFileFromZip(path, "res/drawable/image2.9.png");
                    Assert.IsNotNull(data, "image2.9.png should be in {0}android/bin/packaged_resources",
                                     proj.IntermediateOutputPath);
                    png = PNGChecker.LoadFromBytes(data);
                    Assert.IsTrue(png.Is9Patch, "image2.9.png should have been processed into a 9 patch image.");
                    data = ZipHelper.ReadFileFromZip(path, "res/drawable-hdpi-v4/common_signin_btn_icon_normal_dark.9.png");
                    Assert.IsNotNull(data, "common_signin_btn_icon_normal_dark.9.png should be in {0}android/bin/packaged_resources",
                                     proj.IntermediateOutputPath);
                    png = PNGChecker.LoadFromBytes(data);
                    Assert.IsTrue(png.Is9Patch, "common_signin_btn_icon_normal_dark.9.png should have been processed into a 9 patch image.");
                    Directory.Delete(Path.Combine(Root, projectPath), recursive: true);
                }
            }
        }