citrix / citrix-mam-sdks

The MAM SDK instrument your apps to enable enforcing policies and controls that are configured in Citrix Endpoint Management.
https://developer.cloud.com/citrixworkspace/mobile-application-integration
11 stars 4 forks source link

iOS 15 - ERROR: Unknown loader command found in the application binary image #51

Closed raphaelguye closed 2 years ago

raphaelguye commented 2 years ago

Description

There is an error at build time for iOS App with the iOS Deployment Target is set to 15.0. project-config-ios15

Expected behaviour

Build is working with same output we have for iOS 14: ios14-success

Actual behaviour

2021-10-20 11:35:36.787 CGAppCLPrepTool[2926:78706] [ToolkitLib] ERROR:  Unknown loader command found  in the application binary image.
ERROR:  Unknown loader command found  in the application binary image.
------------------------------
2021-10-20 11:35:36.790 CGAppCLPrepTool[2926:78706] [CommandLine] ERROR:  Unknown loader command found  in the application binary image.
------------------------------
ios15-error

Step to reproduce

  1. Download the sample project from https://github.com/raphaelguye/DemoCitrixMam
  2. Open the project DemoCitrixMam.xcodeproj
  3. Fix the Code signing if necessary
  4. Build with 'Any iOS Device' (not with the simulator)

NB: You can come back on commit c077785bed04715c81d4a3db06ddc11122568599 to have a success build on iOS 14 (check the history)

GeroHerkenrath commented 2 years ago

Can confirm that this happens, but I want to point out that it's apparently the CGAppCLPrepTool tool that is included in the SDK that causes this error. The actual app builds fine (i.e. if you do not create the MDX file you get a valid app bundle).

raphaelguye commented 2 years ago

Yes that's right. But we need the MDX file to be able to deploy the app on our MDM store. I don't see another workaround, right ?

jaspreetsingh-citrix commented 2 years ago

Hi @raphaelguye, I downloaded the project, and the deployment target was already set to iOS15, but I'm able to successfully create the .mdx file without any errors. To better analyze the error in question, I would need more logs. In the "Create MDX file" script, please add two additional params "-logWriteLevel 4 -logDisplayLevel 4" to the SdkPrep command. And after running into this issue, please share the build logs from Xcode and also logs from the DemoCitrixMam/CitrixMam/Tools/logs directory.

GeroHerkenrath commented 2 years ago

@raphaelguye Yes, of course, but I thought it might help pointing this out. Not just for the SDK team to fix it, also to you, because at least you can continue developing (i.e. building the app and run it on your dev device, which already is configured to run dev installs even without creating an MDX, right?). In my project I have the MDX script in its own wrapper shell script, so it's easy to ignore the error output it gives here (but I can still see its output).

@jaspreet1 It really surprises me that you cannot reproduce the error as the demo project is completely self-contained. Are you sure you set the target to "Any iOS Device" (or a physically connected device) and not a simulator? The problem appears to only occur when building for arm64, not x86_64. Also, there seems to be another bug in the CGAppCLPrepTool as you cannot set both, -logWriteLevel and -logDisplayLevel to 4, then it exits with this:

Showing All Messages
Argument (4) is given twice, please give all arguments only once.
2021-10-21 11:34:31.305 CGAppCLPrepTool[5301:174001] 
--------------------------------------------------------- 
SdkPrep Command 
--------------------------------------------------------- 
CGAppCLPrepTool SdkPrep -in INPUTFILE -appDesc DESCRIPTION  

 -in INPUTFILE              ==>  (Required)Name of the input app file
 -out OUTPUTFILE            ==>  (Required)Name of the output mdx file
 -packageId GUID            ==>  (Required)Package identifier GUID
 -appType TYPE              ==>  (Required)App type (General, Premium, Enterprise)
 -storeURL url              ==>  (Required)http://appstoreaddress/adHoc
 -entitlements PATH         ==>  (Required)Path to entitlements file
 -appIdPrefix APP_ID_PREFIX ==>  (Optional)Application Identifier Prefix (often the same as the Team ID)
 -appDesc DESCRIPTION       ==>  (Optional)Description of the package 
 -minPlatform VERSION       ==>  (Optional)Minimum supported platform version 
 -maxPlatform VERSION       ==>  (Optional)Maximum supported platform version 
 -excludedDevices DEVICES   ==>  (Optional)A list of device type the App is not allowed to run 
 -adalClientID  ADALCLIENTID ==>  (Optional) store or overwrite specified Intune ADAL ClientId setting in info.plist (supports multi tenant Intune ClientId)
 -adalNSGResource  ADALRESOURCE ==>  (Optional) store or overwrite specified  Intune ADAL NetScaler Gateway Resource setting in info.plist (supports multi tenant Intune ClientId)

---------------EXAMPLE-------------------- 

CGAppCLPrepTool SdkPrep -in "input.app -out "output.mdx" -appDesc "Application description" -minPlatform "5.1" 
Note: This command only works on .app files and is typically issued within Xcode post build step

---------------EXAMPLE-------------------- 
--------------------------------------------------------- 

Command Line Interface for MDX Toolkit, version 20.5.0.0 (Env:Test)

(btw, this output needs to be updated, the appType TYPE does not include the parameter we have to use, which would be sdkapp...)

I assume the difference between those log level parameters is only whether it outputs the issue to the console/stderr or into the log file (at least I do not see any difference when trying them individually, besides, there's no difference between using levels 3 and 4 in each combination). For me that produces this output:

2021-10-21 11:33:05 [CommandLine] 

Validating input parameters......
------------------------------

2021-10-21 11:33:05 [CommandLine] Content path: /Users/gero/Desktop/DemoCitrixMam-main/DemoCitrixMam/CitrixMam/Tools/Data
2021-10-21 11:33:05 [ToolkitLib] ContentPath is /Users/gero/Desktop/DemoCitrixMam-main/DemoCitrixMam/CitrixMam/Tools/Data
2021-10-21 11:33:05 [MachORebuildLib] checkLoadCommands: i 0 cmd 0x105efb020 code 0x19 cmdsize 72 Mask 0x7

2021-10-21 11:33:05 [MachORebuildLib] checkLoadCommands: i 1 cmd 0x105efb068 code 0x19 cmdsize 1112 Mask 0x7

2021-10-21 11:33:05 [MachORebuildLib] checkLoadCommands: i 2 cmd 0x105efb4c0 code 0x19 cmdsize 312 Mask 0x7

2021-10-21 11:33:05 [MachORebuildLib] checkLoadCommands: i 3 cmd 0x105efb5f8 code 0x19 cmdsize 232 Mask 0x7

2021-10-21 11:33:05 [MachORebuildLib] checkLoadCommands: i 4 cmd 0x105efb6e0 code 0x19 cmdsize 72 Mask 0x7

2021-10-21 11:33:05 [MachORebuildLib] checkLoadCommands: i 5 cmd 0x105efb728 code 0x80000034 cmdsize 16 Mask 0x7

2021-10-21 11:33:05 [ToolkitLib] ERROR:  Unknown loader command found  in the application binary image.
2021-10-21 11:33:05 [CommandLine] ERROR:  Unknown loader command found  in the application binary image.
------------------------------

2021-10-21 11:33:57 [ToolkitLib] ERROR:  Unknown loader command found  in the application binary image.
2021-10-21 11:33:57 [CommandLine] ERROR:  Unknown loader command found  in the application binary image.
------------------------------
raphaelguye commented 2 years ago

Thanks for your answers.

@jaspreet1 : The logs: Citrix_LogDisplayLevel_4.log Citrix_LogWriteLevel_4.log

I confirm you that I can generate a MDX when building for the Simulator. But not when choosing *Any iOS Device (arm64).

Is is the same for you or are you also able to use arm64 config?

Can I work with the mdx generated by the simulator? I though I should use the arm64 version (which is working on iOS 14).

jaspreetsingh-citrix commented 2 years ago

Thank you @raphaelguye and @GeroHerkenrath for your inputs!

We are aware of this duplicate argument issue and is expected to be fixed in our future releases. (CXM-101281)

You were right, I was using a simulator build. I see the Unknown loader command found issue now. We'll start looking at this error asap. (CXM-101301) In the mean time, .mdx file generated with the simulator device should be good to use. Let me know if you face any issues with that.

jaspreetsingh-citrix commented 2 years ago

Hey, Just a correction here. Even though .mdx from Simulator build be similar to the one we expect, but since the SDKPrep command fails for the iOS, the app won't be ready/compatible with CEM/SecureHub management. Is it a requirement to have the deployment target iOS15 for your Swift app? BTW, this issue is currently seen only in Swift apps, not in ObjC apps.

raphaelguye commented 2 years ago

Yes it is a requirement for us. We can target iOS 15 because of our internal device management policies and we need to benefit of the last APIs released by iOS15.

So if I correctly understood your last answer it will not work with the mdx generated by the simulator build?

jaspreetsingh-citrix commented 2 years ago

Yes, with the currently released CitrixMAMSDK CGAppCLPrepTool tool, the simulator build generated .mdx won't work properly to the .ipa generated without the "CGAppCLPrepTool SdkPrep" step, which only in Swift apps seems to fail with the iOS-15 deployment target.

raphaelguye commented 2 years ago

Understood thank you.

What's your position regarding this issue? Is it something you can fix and release in a minor version? We would need an agenda to make some decision in our project.

Thanks.

raphaelguye commented 2 years ago

When have you planned to release officially the fixed version of CGPrepTool ?

jaspreetsingh-citrix commented 2 years ago

Hi @raphaelguye, Release 22.1.0 has a fix for this issue. It is planned to be released in the first or second week of February..

jaspreetsingh-citrix commented 2 years ago

Hi @raphaelguye, I hope the new release 22.1.0 resolved the issue. Let me know.

raphaelguye commented 2 years ago

Hello @jaspreet1 , yes thank you ! The issue is solved now with the MAM sdk.

I have now the same request for the MDX Toolkit. I know it not the ideal place to ask this question, but I don't have another entry point.

Can you please forward this issue to one of your colleague in charge?

In fact, the same issue is happening with the current stable version of the MDX Toolkit and applications target iOS 15.

jaspreetsingh-citrix commented 2 years ago

Hi @raphaelguye, Thank you for verifying the fix. About the MDX Toolkit, is the app you are wrapping, a Swift app and has a deployment target of iOS15+?

raphaelguye commented 2 years ago

yes @jaspreet1. Swift app target iOS 15+. Wrapped with the MDX toolkit.

jaspreetsingh-citrix commented 2 years ago

Hi @raphaelguye, MDX Toolkit has end-of-life from July 2022. Anyway, Citrix doesn't officially support wrapping Swift apps using MDX Toolkit. Our recommendation is to integrate Citrix MAMSDK with the Swift apps.

jaspreetsingh-citrix commented 2 years ago

Hi @raphaelguye, I believe you might have gotten some help for MDX Toolkit issue as well. Can we close this GitHub issue now?

raphaelguye commented 2 years ago

Yes thank you, we can close the issue. We will use only the MAM sdk in the future for iOS 15+ apps.