Flash3001/Xamarin.Swift

swift dylib files are not included into IPA

andrew-nemtsev opened this issue · 18 comments

I moved to Xamarin.Swift package due to startup crash on 12.2 only devices (observed for Xamarin.Swift4 package).
After adding Xamarin.Swift and removing old Xamarin.Swift4 packages app is running fine on iOS 12.2, but failed to start on iOS 12.1 and lower.

Build log:

Target _SwiftFrameworksMac:
...
Installed: 5.0
Target _SwiftSupportIPA:
...
Installed: 5.0
Target _PackageOnDemandResources:
Directory "obj/iPhone/Release - DEV/ipa/Payload/OnDemandResources/" doesn't exist. Skipping.
Target _ZipIpa:
/usr/bin/zip -r -y "/Volumes/Portable/projects/project/MobileClient/bin/iPhone/Release - DEV/project.ipa" Payload SwiftSupport

otool output for binding framework:

name @rpath/libswiftAccelerate.dylib (offset 24)
name @rpath/libswiftCore.dylib (offset 24)
name @rpath/libswiftCoreAudio.dylib (offset 24)
name @rpath/libswiftCoreData.dylib (offset 24)
name @rpath/libswiftCoreFoundation.dylib (offset 24)
name @rpath/libswiftCoreGraphics.dylib (offset 24)
name @rpath/libswiftCoreImage.dylib (offset 24)
name @rpath/libswiftCoreLocation.dylib (offset 24)
name @rpath/libswiftDarwin.dylib (offset 24)
name @rpath/libswiftDispatch.dylib (offset 24)
name @rpath/libswiftFoundation.dylib (offset 24)
name @rpath/libswiftMetal.dylib (offset 24)
name @rpath/libswiftObjectiveC.dylib (offset 24)
name @rpath/libswiftQuartzCore.dylib (offset 24)
name @rpath/libswiftUIKit.dylib (offset 24)
name @rpath/libswiftos.dylib (offset 24)

I can see Swift targets at build log but SwiftSupport folder is not created inside of IPA.

Following message can be seen at pre iOS 12.2 devices when app is crashed:

symptomsd Attempt to add an app with insufficient id, info

Hey @andrew-nemtsev,

This message is new to me, are you seeing it after you upload your IPA to app store and download the app via TestFlight or is it when you upload the app straight from Visual Studio? If using VS, which version macOS or Windows?

Please also check if you can find any of these messages on your build log https://github.com/Flash3001/Xamarin.Swift/blob/master/SwiftSupport/Shared/BaseVersionCheckTask.cs#L111 (until line 147)

"Attempt to add an app with insufficient id" console error is observed for versions installed from TestFlight.

IDE is VS for Mac 2019 (8.0.1 build 1)
Deployment Target is set to 10.0

"Avoiding to include Swift dylibs because your target OS already includes it." is not seen at Build Output.
Also I see the following logic at [https://github.com/Flash3001/Xamarin.Swift/blob/master/SwiftSupport/Shared/BaseVersionCheckTask.cs#L147](line 147)
Native library is compiled with Swift 4.2 but "Including Swift dylibs because you need a version of Swift lower than 5." is not present at Build Output.

Checking for Regexp at GetMinOsVersion() now

If you open your .APP can you see the libswiftCore.dylib inside the Frameworks folder?

If your libraries are built using Swift 4.2 and you have Xcode 10.2 (seen on your first message) installed the build should fail with the following message:

var msg = $"{item.Key} Framework do not match installed Swift version. " +

No here is no libswiftCore.dylib inside .APP/Fameworks folder.
Also I noticed that here is no any output of this logging in Build Output - only "Installed: 5.0" is present.
Maybe it's a case of empty frameworkAndVersion ?
Am i right that Xamarin.Swift should be included as Nuget package only to application project (not to binding one - exactly as it were for Xamarin.Swift4 use case)?

You are correct, it should only be included on the final project, not the bindings.

Can you check what is the value of _Frameworks on the build output? This value is provided by Xamarin.iOS itself. Is the Swift binding your trying to use included in the app?

There are a few cases where there is no log messages. I need to include some:

private Tuple<string, string> ParseFramework(ITaskItem framework)

if (installedMatch.Success == false)

Bingo! )
One issue is found - Output path contained spaces. After removing spaces from path I got

MobileMessaging Framework: 5.0

in Build Output.
Continue investigation

Looks like problem is solved - after I removed spaces in the name of configuration I found a lot of libswift*.dylib inside of .APP/Frameworks

That is great news. Keep me posted, I want to update the code to cover those cases.

Issue is resolved.
Invalid Swift Support error is not present, app is running fine at iOS 12.2 and lower.

@Flash3001
i was using
iOSCharts 3.2.2.1
Xamarin.Swift 1.0.2
xcode 10.2.1 (10E1001)
Vs for mac 8.0.4 (build 0)

i build and archive for publish to appstore,
the generated ipa dose not include any libswift*.dylib in Payload/APP/Framework folder. as this issue .
the bulding log releated as :

目标 _SwiftSupportIPA: Looking for Swift version on: bin/iPhone/Release/AFORS.APP.iOS.app/Frameworks/Charts.framework/Charts Expected Swift header on: bin/iPhone/Release/AFORS.APP.iOS.app/Frameworks/Charts.framework/Headers/Charts-Swift.h bin/iPhone/Release/AFORS.APP.iOS.app/Frameworks/Charts.framework/Headers/Charts-Swift.h exists. Avoiding to include Swift dylibs because your target OS already includes it. Installed: 5.0.1 Charts Framework: 5.0.1 目标 _PackageOnDemandResources: 目录“obj/iPhone/Release/ipa/Payload/OnDemandResources/”不存在。正在跳过。

and there is another error message maybe useful:
warning: Could not open '/Users/flash/Library/Developer/Xcode/DerivedData/Charts-fepxlvsclbgrvufyacqchsxgpgau/Build/Intermediates.noindex/Charts.build/Release-iphoneos/Charts.build/Objects-normal/arm64/Charts.swiftmodule'

@azraelrabbit are you targeting iOS 12.2? Your message says: Avoiding to include Swift dylibs because your target OS already includes it.

It is expected when your Deployment Target on Info.plist is 12.2. If you change that to anything lower than 12.2 the files will be included.

Was your app rejected, crashed or you just noticed the lack of the files?

yes , my app rejected when i upload to appstore, it reply the swiftsupport folder is empty.

thanks for your help,
i 'll try to downgrade deployment target to testing

more question,
if i change the Deployment Target to lower version, do i need the package_ipa_default.sh to repack again?

thanks again. my app upload to appstore succesfully.
my operation step:

  1. change Deployment Target to 11.x(12.x do not work), in Info.plist
  2. build and archive for publish, then sign and generate .ipa for appstore.
  3. unarchive the generated .ipa ,get the Payload folder.
  4. use package_ipa_default.sh to repack.
  5. upload the repacked ipa file to appstore

then my app in App Store Connect is waiting for publish.

thanks a lot @Flash3001

Hey @azraelrabbit . I think it is a real bug on the library. The SwiftSupport folder is always being created, I will fix.

Bingo! )
One issue is found - Output path contained spaces. After removing spaces from path I got

MobileMessaging Framework: 5.0

in Build Output.
Continue investigation

Looks like problem is solved - after I removed spaces in the name of configuration I found a lot of libswift*.dylib inside of .APP/Frameworks

This is the exact error I'm getting. If there is a space symbol in the output path no Swift dylibs are copied to the application. And if Device-specific builds are enabled the output path looks something like .../bin/iPhoneSimulator/Debug/device-builds/iphone 5-10.3/SampleApp.iOS.app/, so this option has to be disabled to get Swift files copied.

@Flash3001 should this be considered as a bug in Xamarin.Swift?