@@ -298,13 +298,16 @@ export function addExpoPre55ShellPatchScriptPhase(
298298 appTargetName : string ;
299299 }
300300) {
301+ const applicationTargets = getApplicationTargetNames ( project ) ;
301302 const resolvedAppTargetName =
302- appTargetName || getApplicationTargetName ( project ) ;
303+ appTargetName || getApplicationTargetName ( applicationTargets ) ;
303304
304305 if ( ! resolvedAppTargetName ) {
305- throw new SourceModificationError (
306- 'Could not determine the iOS app target name from the Xcode project. Please provide the app target name in plugin options.'
307- ) ;
306+ const errorMessage =
307+ applicationTargets . length > 1
308+ ? `Multiple iOS application targets found in the Xcode project (${ applicationTargets . join ( ', ' ) } ). Please set ios.appTargetName in plugin options.`
309+ : 'Could not determine the iOS app target name from the Xcode project. Please provide the app target name in plugin options.' ;
310+ throw new SourceModificationError ( errorMessage ) ;
308311 }
309312
310313 project . addBuildPhase (
@@ -325,10 +328,21 @@ export function addExpoPre55ShellPatchScriptPhase(
325328}
326329
327330/**
328- * Returns the iOS application target name from PBXNativeTarget section.
331+ *
332+ * @param applicationTargets iOS application target names
333+ * @returns First iOS application target name if there is exactly one, otherwise null
329334 */
330- function getApplicationTargetName ( project : XcodeProject ) : string | null {
335+ function getApplicationTargetName ( applicationTargets : string [ ] ) : string | null {
336+ if ( applicationTargets . length !== 1 ) return null ;
337+ return applicationTargets [ 0 ] ;
338+ }
339+
340+ /**
341+ * Returns iOS application target names from PBXNativeTarget section.
342+ */
343+ function getApplicationTargetNames ( project : XcodeProject ) : string [ ] {
331344 const nativeTargets = project . pbxNativeTargetSection ( ) ;
345+ const applicationTargets = new Set < string > ( ) ;
332346
333347 for ( const [ key , value ] of Object . entries ( nativeTargets ) ) {
334348 if ( key . endsWith ( '_comment' ) ) continue ;
@@ -340,10 +354,12 @@ function getApplicationTargetName(project: XcodeProject): string | null {
340354 const targetName = String ( target ?. name ?? '' )
341355 . replace ( / " / g, '' )
342356 . trim ( ) ;
343- if ( targetName ) return targetName ;
357+ if ( targetName ) {
358+ applicationTargets . add ( targetName ) ;
359+ }
344360 }
345361
346- return null ;
362+ return [ ... applicationTargets ] ;
347363}
348364
349365/**
0 commit comments