@@ -319,7 +319,6 @@ local function getLiveBuildCopyIconScript(src, dest, options)
319
319
end
320
320
321
321
---- ----------------------------------------------------------------------------
322
-
323
322
local function getCodesignScript ( entitlements , path , identity , developerBase )
324
323
325
324
codesign_allocate = xcodetoolhelper [' codesign_allocate' ]
@@ -350,6 +349,82 @@ export PATH="$DEVELOPER_BASE/Platforms/iPhoneOS.platform/Developer/usr/bin:$DEVE
350
349
return devbase_shell .. export_path .. script .. cmd
351
350
end
352
351
352
+ local function getCodesignAPPXScriptAndPackage (path , identity , entitlements , developerBase , bundleId , isBuildForDistribution )
353
+
354
+ local codesign_allocate = xcodetoolhelper [' codesign_allocate' ]
355
+ local codesign = xcodetoolhelper [' codesign' ]
356
+
357
+ -- Remove extended attributes that may interfere with codesign
358
+ local appxPath = path :gsub (' ["\' ]' , " " ) .. " /PlugIns"
359
+ local removeXattrs = " /usr/bin/xattr -cr " .. quoteString (appxPath )
360
+
361
+ -- Quote paths to handle spaces
362
+ codesign_allocate = quoteString (codesign_allocate )
363
+ codesign = quoteString (codesign )
364
+ developerBase = quoteString (developerBase )
365
+
366
+ -- Shell script setup
367
+ local devbase_shell = " DEVELOPER_BASE=" .. developerBase .. " \n "
368
+ local export_path = [==[
369
+ export PATH="$DEVELOPER_BASE/Platforms/iPhoneOS.platform/Developer/usr/bin:$DEVELOPER_BASE/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
370
+ ]==]
371
+
372
+ local script = ' export CODESIGN_ALLOCATE=' .. codesign_allocate .. ' \n '
373
+
374
+ -- Start command with attribute cleanup
375
+ local cmd = removeXattrs
376
+
377
+ -- Check if PlugIns folder exists and sign each .appex file
378
+ if lfs .attributes (appxPath , " mode" ) == " directory" then
379
+ for file in lfs .dir (appxPath ) do
380
+ if file :match (" %.appex$" ) then
381
+ local appexPath = appxPath .. " /" .. file
382
+ local infoPlist = quoteString (appexPath .. " /Info.plist" )
383
+
384
+ -- Extract CFBundleIdentifier and get the last component
385
+ local getBundleIdCmd = " /usr/bin/plutil -extract CFBundleIdentifier xml1 -o - " .. infoPlist ..
386
+ " | sed -n 's/.*<string>\\ (.*\\ )<\\ /string>.*/\\ 1/p' | awk -F'.' '{print $NF}'"
387
+
388
+ -- Set new CFBundleIdentifier
389
+ local setBundleIdCmd = " newBundleId=\" " .. bundleId .. " .$(" .. getBundleIdCmd .. " )\" && " ..
390
+ " /usr/bin/plutil -replace CFBundleIdentifier -string \" $newBundleId\" " .. infoPlist
391
+
392
+ local bundleIdOutput = io.popen (getBundleIdCmd ):read (" *a" ):gsub (" %s+" , " " ) -- Clean up any extra spaces
393
+
394
+ -- Run the command to update CFBundleIdentifier
395
+ runScript (setBundleIdCmd )
396
+
397
+ -- Determine which mobile provision profile to use based on `isBuildForDistribution`
398
+ local mobileProvisionPath = path :gsub (' ["\' ]' , " " ) .. " /iOSAppxFiles/" .. bundleIdOutput .. " /"
399
+ local selectedProvision = isBuildForDistribution and
400
+ (mobileProvisionPath .. " embedded.mobileprovision" ) or
401
+ (lfs .attributes (mobileProvisionPath .. " embedded_dev.mobileprovision" , " mode" ) == " file" and
402
+ mobileProvisionPath .. " embedded_dev.mobileprovision" or
403
+ mobileProvisionPath .. " embedded.mobileprovision" )
404
+
405
+ if not lfs .attributes (selectedProvision , " mode" ) then
406
+ print (" Warning: Cannot find mobile provision profile for " .. bundleIdOutput ..
407
+ " at " .. selectedProvision .. " This may cause issues with your app." )
408
+ else
409
+ -- Copy the mobile provision profile to the .appex bundle and delete the old one
410
+ local copyMobileProvisionCmd = " cp " .. quoteString (selectedProvision ) .. " " ..
411
+ quoteString (appexPath .. " /embedded.mobileprovision" ) ..
412
+ " && rm -rf " .. quoteString (mobileProvisionPath )
413
+ runScript (copyMobileProvisionCmd )
414
+
415
+ -- Append signing command for .appex
416
+ cmd = cmd .. " && " .. codesign .. " --verbose -f -s " .. quoteString (identity ) ..
417
+ " --entitlements " .. entitlements .. " " .. quoteString (appexPath )
418
+ end
419
+ end
420
+ end
421
+ end
422
+
423
+ return devbase_shell .. export_path .. script .. cmd
424
+ end
425
+
426
+
427
+
353
428
354
429
local function getCodesignFrameworkScript ( path , identity , developerBase )
355
430
439
514
440
515
---- ----------------------------------------------------------------------------
441
516
517
+ -- check if app has any appx in app folder
518
+ local function checkAppHasAPPX ( appPath )
519
+ local pluginsPath = appPath :gsub (' ["\' ]' , " " ) .. " /PlugIns"
520
+
521
+ -- Check if PlugIns folder exists
522
+ if lfs .attributes (pluginsPath , " mode" ) == " directory" then
523
+
524
+ -- Find .appex files inside PlugIns
525
+ for file in lfs .dir (pluginsPath ) do
526
+ if file :match (" %.appex$" ) then
527
+ return true
528
+ end
529
+ end
530
+ else
531
+ return false
532
+ end
533
+ end
534
+
535
+ ---- ----------------------------------------------------------------------------
536
+
442
537
-- Assumes pwd is same as this script's directory
443
538
444
539
local templateXcent = [[
@@ -1020,10 +1115,20 @@ local function packageApp( options )
1020
1115
return errMsg
1021
1116
end
1022
1117
1023
-
1024
1118
local entitlements = quoteString ( options .tmpDir .. " /entitlements.xcent" )
1025
1119
setStatus (" Signing application with " .. tostring (options .signingIdentityName ))
1026
1120
1121
+ -- codesign embedded appx (iOS Extension Files)
1122
+ if (checkAppHasAPPX (options .appBundleFile )) then
1123
+
1124
+ local result , errMsg = runScript ( getCodesignAPPXScriptAndPackage ( options .appBundleFile :gsub (' ["\' ]' , " " ), options .signingIdentity , entitlements , iPhoneSDKRoot , options .bundleid , builtForAppStore ) )
1125
+ if result ~= 0 then
1126
+ errMsg = " ERROR: code signing embedded appx failed: " .. tostring (errMsg )
1127
+ return errMsg
1128
+ end
1129
+ end
1130
+
1131
+
1027
1132
local result , errMsg = runScript ( getCodesignScript ( entitlements , appBundleFileUnquoted , options .signingIdentity , iPhoneSDKRoot ) )
1028
1133
1029
1134
if result ~= 0 then
@@ -1388,6 +1493,7 @@ function iPhonePostPackage( params )
1388
1493
local osPlatform = params .osPlatform
1389
1494
local err = nil
1390
1495
1496
+ local iPhoneSDKRoot = sdkRoot or " /Applications/Xcode.app/Contents/Developer"
1391
1497
-- Make available globally
1392
1498
xcodetoolhelper = params .xcodetoolhelper
1393
1499
@@ -1564,6 +1670,7 @@ function iPhonePostPackage( params )
1564
1670
end
1565
1671
end
1566
1672
1673
+
1567
1674
-- inject live build settings
1568
1675
if options .liveBuild then
1569
1676
-- 1. set options.settings.iph one.plist.NSAppTransportSecurity.NSAllowsArbitraryLoads
@@ -1590,11 +1697,13 @@ function iPhonePostPackage( params )
1590
1697
return result
1591
1698
end
1592
1699
1593
- result = packageApp ( options )
1594
1700
1701
+ result = packageApp ( options )
1702
+
1595
1703
if result then
1596
1704
return result
1597
1705
end
1706
+
1598
1707
end
1599
1708
1600
1709
return err
0 commit comments