|
9 | 9 | using Xamarin.ProjectTools;
|
10 | 10 | using Microsoft.Android.Build.Tasks;
|
11 | 11 | using Microsoft.Build.Framework;
|
| 12 | +using Xamarin.Tools.Zip; |
12 | 13 |
|
13 | 14 | namespace Xamarin.Android.Build.Tests
|
14 | 15 | {
|
@@ -437,6 +438,43 @@ public void OnUpdate (Java.Lang.Object p0)
|
437 | 438 | }
|
438 | 439 | }
|
439 | 440 |
|
| 441 | + [Test] |
| 442 | + public void AndroidLibraryPackFalseExcludesJarFromAar () |
| 443 | + { |
| 444 | + var binding = new XamarinAndroidBindingProject () { |
| 445 | + IsRelease = true, |
| 446 | + }; |
| 447 | + // Add a jar with Pack='false' - should not be included in AAR |
| 448 | + binding.OtherBuildItems.Add (new AndroidItem.AndroidLibrary ("Jars\\test-pack-false.jar") { |
| 449 | + BinaryContent = () => ResourceData.JavaSourceJarTestJar, |
| 450 | + MetadataValues = "Pack=false;Bind=false", |
| 451 | + }); |
| 452 | + // Add a jar with Pack='true' (default) - should be included in AAR |
| 453 | + binding.OtherBuildItems.Add (new AndroidItem.AndroidLibrary ("Jars\\test-pack-true.jar") { |
| 454 | + BinaryContent = () => ResourceData.JavaSourceJarTestJar, |
| 455 | + MetadataValues = "Bind=false", |
| 456 | + }); |
| 457 | + |
| 458 | + using (var bindingBuilder = CreateDllBuilder ()) { |
| 459 | + Assert.IsTrue (bindingBuilder.Build (binding), "binding build should have succeeded"); |
| 460 | + |
| 461 | + // Check that the AAR file was created |
| 462 | + var aarPath = Path.Combine (Root, bindingBuilder.ProjectDirectory, binding.OutputPath, "UnnamedProject.aar"); |
| 463 | + FileAssert.Exists (aarPath); |
| 464 | + |
| 465 | + // Extract and examine AAR contents |
| 466 | + using (var aar = ZipArchive.Open (aarPath, FileMode.Open)) { |
| 467 | + // test-pack-false.jar should NOT be in the AAR because Pack='false' |
| 468 | + var packFalseEntry = aar.Where (e => e.FullName.Contains ("test-pack-false")).FirstOrDefault (); |
| 469 | + Assert.IsNull (packFalseEntry, "Jar with Pack='false' should not be included in AAR"); |
| 470 | + |
| 471 | + // test-pack-true.jar should be in the AAR (default Pack='true') |
| 472 | + var packTrueEntry = aar.Where (e => e.FullName.Contains ("test-pack-true") || e.FullName.StartsWith ("libs/")).FirstOrDefault (); |
| 473 | + Assert.IsNotNull (packTrueEntry, "Jar with Pack='true' (default) should be included in AAR"); |
| 474 | + } |
| 475 | + } |
| 476 | + } |
| 477 | + |
440 | 478 | [Test]
|
441 | 479 | public void RemoveEventHandlerResolution ()
|
442 | 480 | {
|
|
0 commit comments