@@ -569,5 +569,53 @@ public void CheckForInvalidVersionCode (string versionCode, string versionCodePa
569569 Assert . AreEqual ( manifestFile , errors [ 0 ] . File , $ "Error File should have been { manifestFile } ") ;
570570 Directory . Delete ( Path . Combine ( Root , path ) , recursive : true ) ;
571571 }
572+
573+ [ Test ]
574+ public void Aapt2LinkPassesMinSdkVersion ( )
575+ {
576+ var path = Path . Combine ( Root , "temp" , TestName ) ;
577+ Directory . CreateDirectory ( path ) ;
578+ var resPath = Path . Combine ( path , "res" ) ;
579+ Directory . CreateDirectory ( resPath ) ;
580+ var engine = new MockBuildEngine ( TestContext . Out ) ;
581+ var manifestFile = Path . Combine ( path , "AndroidManifest.xml" ) ;
582+ File . WriteAllText ( manifestFile , @"<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='Foo.Foo'>
583+ <uses-sdk android:minSdkVersion='26' android:targetSdkVersion='31' />
584+ <application android:label='Test' />
585+ </manifest>" ) ;
586+
587+ CallAapt2Compile ( engine , resPath , path , path ) ;
588+
589+ int platform = AndroidSdkResolver . GetMaxInstalledPlatform ( ) ;
590+ var task = new Aapt2Link {
591+ BuildEngine = engine ,
592+ ToolPath = GetPathToAapt2 ( ) ,
593+ ResourceDirectories = new ITaskItem [ ] { new TaskItem ( resPath ) } ,
594+ ManifestFiles = new ITaskItem [ ] { new TaskItem ( manifestFile ) } ,
595+ AndroidManifestFile = new TaskItem ( manifestFile ) ,
596+ CompiledResourceFlatArchive = new TaskItem ( Path . Combine ( path , "compiled.flata" ) ) ,
597+ OutputFile = Path . Combine ( path , "resources.apk" ) ,
598+ AssemblyIdentityMapFile = Path . Combine ( path , "foo.map" ) ,
599+ JavaPlatformJarPath = Path . Combine ( AndroidSdkPath , "platforms" , $ "android-{ platform } ", "android.jar" ) ,
600+ JavaDesignerOutputDirectory = Path . Combine ( path , "java" )
601+ } ;
602+
603+ // Override GenerateCommandLineCommands to capture the command line
604+ var commandLine = ( string [ ] ) typeof ( Aapt2Link )
605+ . GetMethod ( "GenerateCommandLineCommands" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance )
606+ . Invoke ( task , new object [ ] { manifestFile , null , Path . Combine ( path , "resources.apk" ) } ) ;
607+
608+ // Verify that --min-sdk-version 26 is present in the command line
609+ bool foundMinSdkVersion = false ;
610+ for ( int i = 0 ; i < commandLine . Length - 1 ; i ++ ) {
611+ if ( commandLine [ i ] == "--min-sdk-version" && commandLine [ i + 1 ] == "26" ) {
612+ foundMinSdkVersion = true ;
613+ break ;
614+ }
615+ }
616+
617+ Assert . IsTrue ( foundMinSdkVersion , $ "--min-sdk-version 26 should be present in aapt2 command line. Command: { string . Join ( " " , commandLine ) } ") ;
618+ Directory . Delete ( Path . Combine ( Root , path ) , recursive : true ) ;
619+ }
572620 }
573621}
0 commit comments