@@ -213,6 +213,56 @@ public void OverlayManifestTest ([Values] AndroidRuntime runtime)
213213 }
214214 }
215215
216+ [ Test ]
217+ public void OverlayManifestIncrementalBuildTest ( [ Values ] AndroidRuntime runtime )
218+ {
219+ const bool isRelease = true ;
220+ if ( IgnoreUnsupportedConfiguration ( runtime , release : isRelease ) ) {
221+ return ;
222+ }
223+ var proj = new XamarinAndroidApplicationProject ( ) {
224+ IsRelease = isRelease ,
225+ ManifestMerger = "manifestmerger.jar" ,
226+ } ;
227+ proj . SetRuntime ( runtime ) ;
228+ proj . AndroidManifest = @"<?xml version=""1.0"" encoding=""utf-8""?>
229+ <manifest xmlns:android=""http://schemas.android.com/apk/res/android"" android:versionCode=""1"" android:versionName=""1.0"" package=""foo.foo"">
230+ <application android:label=""foo"">
231+ </application>
232+ </manifest>" ;
233+ var overlay = new BuildItem ( "AndroidManifestOverlay" , "ManifestOverlay.xml" ) {
234+ TextContent = ( ) => @"<?xml version=""1.0"" encoding=""utf-8""?>
235+ <manifest xmlns:android=""http://schemas.android.com/apk/res/android"">
236+ <uses-permission android:name=""android.permission.CAMERA"" />
237+ </manifest>
238+ "
239+ } ;
240+ proj . OtherBuildItems . Add ( overlay ) ;
241+ using ( var b = CreateApkBuilder ( cleanupAfterSuccessfulBuild : false , cleanupOnDispose : false ) ) {
242+ Assert . IsTrue ( b . Build ( proj ) , "First build should have succeeded." ) ;
243+ var text = b . Output . GetIntermediaryAsText ( "android/AndroidManifest.xml" ) ;
244+ StringAssert . Contains ( "android.permission.CAMERA" , text , "Merged manifest should contain the initial overlay permission." ) ;
245+ StringAssert . DoesNotContain ( "android.permission.RECORD_AUDIO" , text , "Merged manifest should not contain the updated overlay permission yet." ) ;
246+
247+ Assert . IsTrue ( b . Build ( proj , doNotCleanupOnUpdate : true , saveProject : false ) , "Second build should have succeeded." ) ;
248+ b . Output . AssertTargetIsSkipped ( "_ManifestMerger" ) ;
249+
250+ overlay . TextContent = ( ) => @"<?xml version=""1.0"" encoding=""utf-8""?>
251+ <manifest xmlns:android=""http://schemas.android.com/apk/res/android"">
252+ <uses-permission android:name=""android.permission.CAMERA"" />
253+ <uses-permission android:name=""android.permission.RECORD_AUDIO"" />
254+ </manifest>
255+ " ;
256+ proj . Touch ( "ManifestOverlay.xml" ) ;
257+
258+ Assert . IsTrue ( b . Build ( proj , doNotCleanupOnUpdate : true , saveProject : false ) , "Third build should have succeeded." ) ;
259+ b . Output . AssertTargetIsNotSkipped ( "_ManifestMerger" ) ;
260+
261+ text = b . Output . GetIntermediaryAsText ( "android/AndroidManifest.xml" ) ;
262+ StringAssert . Contains ( "android.permission.RECORD_AUDIO" , text , "Merged manifest should include permissions from the updated overlay." ) ;
263+ }
264+ }
265+
216266 [ Test ]
217267 public void RemovePermissionTest ( [ Values ] AndroidRuntime runtime )
218268 {
0 commit comments