tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

Problem with uploading into App Store Connect (flutter) #2113

Open TDMNS opened 2 years ago

TDMNS commented 2 years ago

Hi all. I ran into this problem while uploading an app on App Store Connect: Introductory: my application uses the tdlib library (for telegram), written on a cross-platform (flutter), made and launched on Android, launched on iOS, but cannot be loaded into TestFlight. An error occurs: Dear developer, We identified one or more issues with a recent delivery for your app, “someName” 0.0.22 (30). Please correct the following issues, then upload again. ITMS-90429: Invalid Swift Support - The files libswiftDarwin.dylib libswiftMetal.dylib libswiftCoreAudio.dylib libswiftQuartzCore.dylib libswiftos.dylib libswiftCoreMedia.dylib, libswiftCore.dylib, libswiftFoundation.dylib, libswiftCoreImage.dylib aren't at the expected location /Payload/Runner.app/Frameworks. Move the file to the expected location, rebuild your app using the current public (GM) version of Xcode, and resubmit it. Our task is to upload the application to Testflight. Tried to fix: tried to disable the check when loading MP in the AppStore. Hypotheses - Problem in validating .Swift files in Flutter that shouldn't be validated. How to get rid of this problem is unknown. When we uncheck Strip Swift Symbols, the validation is still carried out in the Flutter libraries. We plan to test the possibility of loading another application in Testflight with the tdlib library. Rebuild library (built on intel in latest xcode, tried to boot from intel and M1) Tell me, can someone come across such a problem?

TDMNS commented 2 years ago

Tried when loading 2 applications. I came to the conclusion that this is a library problem.

levlam commented 2 years ago

Do you include TDLib as Universal XCFramework and build it as described in https://github.com/tdlib/td/tree/master/example/ios?

TDMNS commented 2 years ago

Yes! I'm building Xcframwork and everything works fine in Xcode and Flutter, but it doesn't load in the App Store.

levlam commented 2 years ago

Issues with uploading apps to App store were common previously, but all of them were solved by using XCFramework instead of plain dynamic libraries. https://developer.apple.com/library/archive/technotes/tn2435/_index.html#//apple_ref/doc/uid/DTS40017543-CH1-TROUBLESHOOTING-BUNDLE_ERRORS mentions exactly this reason as the cause of "Invalid Swift Support".

TDMNS commented 2 years ago

We use XCFramework... And get this error.

Anfet commented 2 years ago

Same issue. Android works fine, IOS app connect rejects the library. Any workaround? Or maybe some updated script for assembling?

Kylmakalle commented 2 years ago

The issue

I was able to contact with issue author and managed to get it works and publish their app to AppStore Connect.

So, levlam mentioned exact Apple docs that describes the issue.

Dynamic libraries outside of a framework bundle, which typically have the file extension .dylib, are not supported on iOS...

Current example/ios provides a build of .dylibs packed into .xcframework for compatibility with arm64 macs, since it's impossible to have a fat binary (more on that here https://github.com/tdlib/td/pull/1620#issuecomment-884468303)

Well, it will work for any local or debug iOS builds, ad hoc distribution and etc., but will not work for AppStore distribution.

Is it a tdlib issue then...?)

Solutions so far

Wrap .dylib in a .framework

That's mentioned in Apple docs.

  1. So you need to create a wrapper with some "fake" .framework. This StackOverflow answer may help a lot. https://stackoverflow.com/a/62962641

  2. You will also need to redefine the -id with install_name_tool of a tdlib binary since dylib is now wrapped. And properly setup your Runpath Search paths. This StackOverflow answer may help. https://stackoverflow.com/questions/9798623/how-to-properly-set-run-paths-search-paths-and-install-names

  3. [Flutter] As for me, I was unable to properly setup tdlib's @rpath in flutter, so it required me to provide a full path to binary like @executable_path/Frameworks/libtdjson_wrapper.framework/libtdjson

P.S. You can combine all of these frameworks in one .xcframework if needed. Take a look at manuals in the internet. Or this script that i'm using for my pre-built binaries.

P.P.S. Be aware of DSYMs. I've not tested how it will work with this fake .framework.

Use static library

After you've build tdlib, you will find both dynamic and static libs at example/ios/build/install-<PLATFORM>/lib. These libs are eligible to be linked and embedded in iOS app for AppStore.

Here I will advertise some pre-built binaries by me at Swiftgram/TDLibFramework. And here's how you may integrate it to your Flutter/Cocoapods project.

Kylmakalle commented 2 years ago

I will let @levlam decide on the future of this issue, here's our options

  1. Update the script so it will wrap .dylib in .framework. (Remember, .dylib is still eligible for local builds & ad-hoc distribution and fully eligible for macOS AppStore builds)
  2. Switch to static libraries in this example
  3. Take a note in a readme like Apple does (IMHO, it's really lacks of exact steps and information. We may also link this discussion.)

    If your project will be submitted to the App Store you will need to package the ***.dylib into a Framework in order to avoid an iTunes Connect error. To package the framework properly, follow these steps.

levlam commented 2 years ago

I will keep this issue open until TDLib build examples are updated, or Apple's policy is changed.

From the proposed options, I think that wrapping .dylib in .framework would be the best approach.

Wolfaks commented 1 year ago

Hello. Has there been a solution? The methods described above are too complicated to understand. Please write a more detailed instruction with all the commands that need to be executed with .dylib files in order for the application to be allowed on the App Store. Thanks

Wolfaks commented 1 year ago

@Kylmakalle These points are very unclear. Are there more detailed instructions? Thanks.

You will also need to redefine the -id with install_name_tool of a tdlib binary since dylib is now wrapped. And properly setup your Runpath Search paths. This StackOverflow answer may help. https://stackoverflow.com/questions/9798623/how-to-properly-set-run-paths-search-paths-and-install-names

[Flutter] As for me, I was unable to properly setup tdlib's @rpath in flutter, so it required me to provide a full path to binary like @executable_path/Frameworks/libtdjson_wrapper.framework/libtdjson

Kylmakalle commented 1 year ago

@Wolfaks I’m unable to post detailed instructions… yet. Referenced Stackoverflow threads have enough info to kick off with tdlib in AppStore.

Wolfaks commented 1 year ago

I was finally able to successfully submit the app to the App Store. What I've done:

1) Used this instruction to build the library: https://github.com/tdlib/td/tree/master/example/ios

2) Fulfilled the first point from instruction @Kylmakalle: So you need to create a wrapper with some "fake" .framework. This StackOverflow answer may help a lot. https://stackoverflow.com/a/62962641 Command: (for each libtdjson.dylib files from the required architecture folders) lipo -create libtdjson.dylib -output libtdjson

Then deleted unnecessary file libtdjson.dylib, moved files libtdjson to folders /libtdjson.framework and ran the command for each new created libtdjson file: (Always first you need to go to the desired folder in the terminal, with the right architecture) install_name_tool -change @rpath/libtdjson.dylib @rpath/libtdjson.framework/libtdjson libtdjson

3) Then for each of the libtdjson files, I ran the command to change the path: (Always first you need to go to the desired folder in the terminal, with the right architecture) install_name_tool -id "@rpath/libtdjson.framework/libtdjson" libtdjson

Then I checked that the paths changed correctly: otool -L libtdjson

Screenshot 2022-12-10 at 13 12 58

4) Added file libtdjson to the folder with file Info.plist for each architecture. (you need to replace the id with your own): `<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

CFBundleExecutable libtdjson CFBundleIdentifier YOUR_BUNDLE_ID.libtdjson MinimumOSVersion 11.0 ` 5) Move entire libtdjson.xcframework folder to ios project and add library to xcode project: Screenshot 2022-12-10 at 13 11 41 Screenshot 2022-12-10 at 13 13 31 Done! Everything works on the iPhone and in the simulator, and my application was also missed in the app store. Thanks to all! 🎉
slender2332 commented 1 year ago

I was finally able to successfully submit the app to the App Store. What I've done:

1. Used this instruction to build the library:
   https://github.com/tdlib/td/tree/master/example/ios

2. Fulfilled the first point from instruction @Kylmakalle:
   `So you need to create a wrapper with some "fake" .framework. This StackOverflow answer may help a lot. https://stackoverflow.com/a/62962641`
   Command: (for each libtdjson.dylib files from the required architecture folders)
   `lipo -create libtdjson.dylib -output libtdjson`

Then deleted unnecessary file libtdjson.dylib, moved files libtdjson to folders /libtdjson.framework and ran the command for each new created libtdjson file: (Always first you need to go to the desired folder in the terminal, with the right architecture) install_name_tool -change @rpath/libtdjson.dylib @rpath/libtdjson.framework/libtdjson libtdjson

3. Then for each of the libtdjson files, I ran the command to change the path: (Always first you need to go to the desired folder in the terminal, with the right architecture)
   `install_name_tool -id "@rpath/libtdjson.framework/libtdjson" libtdjson`

Then I checked that the paths changed correctly: otool -L libtdjson Screenshot 2022-12-10 at 13 12 58

4. Added file libtdjson to the folder with file Info.plist for each architecture. (you need to replace the id with your own):
   `

CFBundleExecutable libtdjson CFBundleIdentifier YOUR_BUNDLE_ID.libtdjson MinimumOSVersion 11.0 `

5. Move entire libtdjson.xcframework folder to ios project and add library to xcode project:
Screenshot 2022-12-10 at 13 11 41 Screenshot 2022-12-10 at 13 13 31

Done! Everything works on the iPhone and in the simulator, and my application was also missed in the app store. Thanks to all! 🎉

Hello , I followed the steps. it works on simulator but not in real iphone . whats possible gone wrong ?

wassmtg commented 1 year ago

Hey guys... Who can tell me how to use tdlib with flutter ? All the existing plugins didn't work.

ivk1800 commented 1 year ago

Hey guys... Who can tell me how to use tdlib with flutter ? All the existing plugins didn't work.

https://github.com/ivk1800/tdlib-dart

hantrungkien commented 1 week ago

@Wolfaks could you please help me to provide a example repository? Many thanks!