@@ -91,27 +91,34 @@ public Foo ()
9191 TextContent = ( ) => {
9292 return "<?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n <ImageView xmlns:android=\" http://schemas.android.com/apk/res/android\" android:src=\" @drawable/IMALLCAPS\" />" ;
9393 }
94- }
94+ } ,
95+ new AndroidItem . AndroidAsset ( "Assets\\ foo\\ foo.txt" ) {
96+ BinaryContent = ( ) => Array . Empty < byte > ( ) ,
97+ } ,
98+ new AndroidItem . AndroidResource ( "Resources\\ layout\\ MyLayout.axml" ) {
99+ TextContent = ( ) => "<?xml version=\" 1.0\" encoding=\" utf-8\" ?><LinearLayout xmlns:android=\" http://schemas.android.com/apk/res/android\" />"
100+ } ,
101+ new AndroidItem . AndroidResource ( "Resources\\ raw\\ bar.txt" ) {
102+ BinaryContent = ( ) => Array . Empty < byte > ( ) ,
103+ } ,
104+ new AndroidItem . AndroidLibrary ( "sub\\ directory\\ foo.jar" ) {
105+ BinaryContent = ( ) => ResourceData . JavaSourceJarTestJar ,
106+ } ,
107+ new AndroidItem . AndroidLibrary ( "sub\\ directory\\ bar.aar" ) {
108+ WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar" ,
109+ } ,
110+ new AndroidItem . AndroidJavaSource ( "JavaSourceTestExtension.java" ) {
111+ Encoding = Encoding . ASCII ,
112+ TextContent = ( ) => ResourceData . JavaSourceTestExtension ,
113+ } ,
95114 }
96115 } ;
97- libB . OtherBuildItems . Add ( new AndroidItem . AndroidAsset ( "Assets\\ foo\\ foo.txt" ) {
98- BinaryContent = ( ) => Array . Empty < byte > ( ) ,
99- } ) ;
100- libB . OtherBuildItems . Add ( new AndroidItem . AndroidResource ( "Resources\\ layout\\ MyLayout.axml" ) {
101- TextContent = ( ) => "<?xml version=\" 1.0\" encoding=\" utf-8\" ?><LinearLayout xmlns:android=\" http://schemas.android.com/apk/res/android\" />"
102- } ) ;
103- libB . OtherBuildItems . Add ( new AndroidItem . AndroidResource ( "Resources\\ raw\\ bar.txt" ) {
104- BinaryContent = ( ) => Array . Empty < byte > ( ) ,
105- } ) ;
106116 libB . OtherBuildItems . Add ( new AndroidItem . AndroidEnvironment ( "env.txt" ) {
107117 TextContent = ( ) => $ "{ env_var } ={ env_val } ",
108118 } ) ;
109119 libB . OtherBuildItems . Add ( new AndroidItem . AndroidEnvironment ( "sub\\ directory\\ env.txt" ) {
110120 TextContent = ( ) => $ "{ env_var } ={ env_val } ",
111121 } ) ;
112- libB . OtherBuildItems . Add ( new AndroidItem . AndroidLibrary ( "sub\\ directory\\ foo.jar" ) {
113- BinaryContent = ( ) => ResourceData . JavaSourceJarTestJar ,
114- } ) ;
115122 libB . OtherBuildItems . Add ( new AndroidItem . AndroidLibrary ( "sub\\ directory\\ arm64-v8a\\ libfoo.so" ) {
116123 BinaryContent = ( ) => Array . Empty < byte > ( ) ,
117124 } ) ;
@@ -120,11 +127,6 @@ public Foo ()
120127 MetadataValues = "Link=x86\\ libfoo.so" ,
121128 BinaryContent = ( ) => Array . Empty < byte > ( ) ,
122129 } ) ;
123- libB . OtherBuildItems . Add ( new AndroidItem . AndroidJavaSource ( "JavaSourceTestExtension.java" ) {
124- Encoding = Encoding . ASCII ,
125- TextContent = ( ) => ResourceData . JavaSourceTestExtension ,
126- Metadata = { { "Bind" , "True" } } ,
127- } ) ;
128130 libB . AddReference ( libC ) ;
129131
130132 activity = libB . Sources . FirstOrDefault ( s => s . Include ( ) == "MainActivity.cs" ) ;
@@ -137,8 +139,10 @@ public Foo ()
137139 "binding" , "bin" , $ "{ libB . ProjectName } .jar") . Replace ( "\\ " , "/" ) ) ;
138140
139141 // Check .aar file for class library
140- var aarPath = Path . Combine ( FullProjectDirectory , libB . OutputPath , $ "{ libB . ProjectName } .aar") ;
142+ var libBOutputPath = Path . Combine ( FullProjectDirectory , libB . OutputPath ) ;
143+ var aarPath = Path . Combine ( libBOutputPath , $ "{ libB . ProjectName } .aar") ;
141144 FileAssert . Exists ( aarPath ) ;
145+ FileAssert . Exists ( Path . Combine ( libBOutputPath , "bar.aar" ) ) ;
142146 using ( var aar = ZipHelper . OpenZip ( aarPath ) ) {
143147 aar . AssertContainsEntry ( aarPath , "assets/foo/foo.txt" ) ;
144148 aar . AssertContainsEntry ( aarPath , "res/layout/mylayout.xml" ) ;
@@ -263,7 +267,26 @@ public void DotNetPack (string dotnetVersion, string platform, int apiLevel)
263267 Sources = {
264268 new BuildItem . Source ( "Foo.cs" ) {
265269 TextContent = ( ) => "public class Foo { }" ,
266- }
270+ } ,
271+ new AndroidItem . AndroidResource ( "Resources\\ raw\\ bar.txt" ) {
272+ BinaryContent = ( ) => Array . Empty < byte > ( ) ,
273+ } ,
274+ new AndroidItem . AndroidLibrary ( "sub\\ directory\\ foo.jar" ) {
275+ BinaryContent = ( ) => ResourceData . JavaSourceJarTestJar ,
276+ } ,
277+ new AndroidItem . AndroidLibrary ( "sub\\ directory\\ bar.aar" ) {
278+ WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar" ,
279+ } ,
280+ new AndroidItem . AndroidJavaSource ( "JavaSourceTest.java" ) {
281+ Encoding = Encoding . ASCII ,
282+ TextContent = ( ) =>
283+ @"package com.xamarin.android.test.msbuildtest;
284+ public class JavaSourceTest {
285+ public String Say (String quote) {
286+ return quote;
287+ }
288+ }" ,
289+ } ,
267290 } ,
268291 ExtraNuGetConfigSources = {
269292 // Projects targeting net6.0 require ref/runtime packs on NuGet.org
@@ -273,12 +296,6 @@ public void DotNetPack (string dotnetVersion, string platform, int apiLevel)
273296 if ( IsPreviewFrameworkVersion ( targetFramework ) ) {
274297 proj . SetProperty ( "EnablePreviewFeatures" , "true" ) ;
275298 }
276- proj . OtherBuildItems . Add ( new AndroidItem . AndroidResource ( "Resources\\ raw\\ bar.txt" ) {
277- BinaryContent = ( ) => Array . Empty < byte > ( ) ,
278- } ) ;
279- proj . OtherBuildItems . Add ( new AndroidItem . AndroidLibrary ( "sub\\ directory\\ foo.jar" ) {
280- BinaryContent = ( ) => ResourceData . JavaSourceJarTestJar ,
281- } ) ;
282299 proj . OtherBuildItems . Add ( new AndroidItem . AndroidLibrary ( "sub\\ directory\\ arm64-v8a\\ libfoo.so" ) {
283300 BinaryContent = ( ) => Array . Empty < byte > ( ) ,
284301 } ) ;
@@ -287,27 +304,30 @@ public void DotNetPack (string dotnetVersion, string platform, int apiLevel)
287304 MetadataValues = "Link=x86\\ libfoo.so" ,
288305 BinaryContent = ( ) => Array . Empty < byte > ( ) ,
289306 } ) ;
290- proj . OtherBuildItems . Add ( new AndroidItem . AndroidJavaSource ( "JavaSourceTest.java" ) {
291- Encoding = Encoding . ASCII ,
292- TextContent = ( ) => @"package com.xamarin.android.test.msbuildtest;
293- public class JavaSourceTest {
294- public String Say (String quote) {
295- return quote;
296- }
297- }
298- " ,
299- Metadata = { { "Bind" , "True" } } ,
300- }
301- ) ;
307+ proj . OtherBuildItems . Add ( new AndroidItem . AndroidLibrary ( default ( Func < string > ) ) {
308+ Update = ( ) => "nopack.aar" ,
309+ WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar" ,
310+ MetadataValues = "Pack=false;Bind=false" ,
311+ } ) ;
302312
303313 var dotnet = CreateDotNetBuilder ( proj ) ;
304314 Assert . IsTrue ( dotnet . Pack ( ) , "`dotnet pack` should succeed" ) ;
305315
306316 var nupkgPath = Path . Combine ( FullProjectDirectory , proj . OutputPath , ".." , $ "{ proj . ProjectName } .1.0.0.nupkg") ;
307317 FileAssert . Exists ( nupkgPath ) ;
308- using ( var nupkg = ZipHelper . OpenZip ( nupkgPath ) ) {
309- nupkg . AssertContainsEntry ( nupkgPath , $ "lib/{ dotnetVersion } -android{ apiLevel } .0/{ proj . ProjectName } .dll") ;
310- nupkg . AssertContainsEntry ( nupkgPath , $ "lib/{ dotnetVersion } -android{ apiLevel } .0/{ proj . ProjectName } .aar") ;
318+ using var nupkg = ZipHelper . OpenZip ( nupkgPath ) ;
319+ nupkg . AssertContainsEntry ( nupkgPath , $ "lib/{ dotnetVersion } -android{ apiLevel } .0/{ proj . ProjectName } .dll") ;
320+ nupkg . AssertContainsEntry ( nupkgPath , $ "lib/{ dotnetVersion } -android{ apiLevel } .0/{ proj . ProjectName } .aar") ;
321+
322+ if ( dotnetVersion != "net6.0" ) {
323+ //TODO: this issue is not fixed in net6.0-android MSBuild targets
324+ nupkg . AssertContainsEntry ( nupkgPath , $ "lib/{ dotnetVersion } -android{ apiLevel } .0/bar.aar") ;
325+ nupkg . AssertDoesNotContainEntry ( nupkgPath , "content/bar.aar" ) ;
326+ nupkg . AssertDoesNotContainEntry ( nupkgPath , "content/sub/directory/bar.aar" ) ;
327+ nupkg . AssertDoesNotContainEntry ( nupkgPath , $ "contentFiles/any/{ dotnetVersion } -android{ apiLevel } .0/sub/directory/bar.aar") ;
328+ nupkg . AssertDoesNotContainEntry ( nupkgPath , $ "lib/{ dotnetVersion } -android{ apiLevel } .0/nopack.aar") ;
329+ nupkg . AssertDoesNotContainEntry ( nupkgPath , "content/nopack.aar" ) ;
330+ nupkg . AssertDoesNotContainEntry ( nupkgPath , $ "contentFiles/any/{ dotnetVersion } -android{ apiLevel } .0/nopack.aar") ;
311331 }
312332 }
313333
0 commit comments