satismeter / satismeter-ios

SatisMeter iOS SDK
https://satismeter.com
MIT License
7 stars 6 forks source link

m1 support adding arm64 for simulator #25

Closed sainttail closed 1 year ago

sainttail commented 2 years ago

I integrate Satismeter via manual installation and got this error when try to build on m1 simulator

In ../SatisMeter/libSatisMeter.a(SatisMeter.o), building for iOS Simulator, but linking in object file built for iOS, file '../SatisMeter/libSatisMeter.a' for architecture arm64

Is there anyway I can solve this?

jsedlacek commented 2 years ago

@sainttail thanks for reporting. Let me check with the team on the m1 support, and get back to you.

iosdec commented 2 years ago

@sainttail try going into your build settings and excluding the arm64 arch for any simulator. I ran into this issue, this solved it.

Screenshot 2022-02-02 at 17 21 26
pjechris commented 2 years ago

@jsedlacek any news? ๐Ÿ™

DelphineGarcia commented 2 years ago

We need to deploy on physical devices so we can't exclude arm64 architecture. To solve this I had to use Rosetta. This makes my Xcode slower of course and I also have some issue with the preview. Do you have any news about supporting arm64 on your side?

jameswwwebster commented 1 year ago

This is quite important for us too. Rosetta gives us a temporary workaround but the slowdown in Xcode is quite unbearable. We'd appreciate support for arm64. ๐Ÿ‘

SergeyPetrachkov commented 1 year ago

Can you guys re-build the lib and pack it into xcframework so it's easier for us to consume the library and run it on simulators?

mixalturek commented 1 year ago

Hi there, I have just checked the content of the archive and from the first look it contains both x86 and arm64 architectures.

file libSatisMeter.a
libSatisMeter.a: Mach-O universal binary with 2 architectures: [x86_64:current ar archive] [arm64]
libSatisMeter.a (for architecture x86_64):  current ar archive
libSatisMeter.a (for architecture arm64):   current ar archive

lipo -detailed_info libSatisMeter.a
Fat header in: libSatisMeter.a
fat_magic 0xcafebabe
nfat_arch 2
architecture x86_64
    cputype CPU_TYPE_X86_64
    cpusubtype CPU_SUBTYPE_X86_64_ALL
    capabilities 0x0
    offset 48
    size 3003144
    align 2^3 (8)
architecture arm64
    cputype CPU_TYPE_ARM64
    cpusubtype CPU_SUBTYPE_ARM64_ALL
    capabilities 0x0
    offset 3003192
    size 2995936
    align 2^3 (8)

It's still possible some additional metadata are missing inside the archive so xcode defaults to the wrong arch. Actually, have you tried the solution/workaround posted by iosdec at the very top?

I am not iOS developer and my last experience with it was about 10 years ago, the same for plain C & C++ and native static libs so I can be totally wrong. Please sorry me in that case :-) The info about the possibly missing metadata is from my friend - he has the knowledge but he doesn't have Mac with M1 CPU for experiments. It should be possible to unpack the archive, somehow improve the metadata and pack everything again to help xcode with the selection. If someone has time and HW for that, please send us list of commands, we will be happy to apply it and fix the issue for all.

SergeyPetrachkov commented 1 year ago

hey @mixalturek! I tried doing the following (I'll just paste stuff from my internal bank of knowledge):

So, basically we need to check the archs like this:

xcrun lipo -l ./Satismeter.framework/Satismeter

it would tell us:

Architectures in the fat file: XXX/Satismeter.framework/Satismeter are: x86_64 arm64

And from that moment we can move forward:

mkdir -p iphoneos
mkdir -p iphonesimulator

cp -R Satismeter.framework/iphoneos/Satismeter.framework
cp -R Satismeter.framework/iphonesimulator/Satismeter.framework

xcrun lipo -remove x86_64 ./iphoneos/Satismeter.framework/Satismeter -o ./iphoneos/Satismeter.framework/Satismeter
xcrun lipo -remove arm64 ./iphonesimulator/Satismeter.framework/Satismeter -o ./iphonesimulator/Satismeter.framework/Satismeter

end then glue it back together

xcodebuild -create-xcframework -framework iphoneos/Satismeter.framework/ -headers  iphoneos/Satismeter.framework/Headers  -framework iphonesimulator/Satismeter.framework/ -headers  iphonesimulator/Satismeter.framework/Headers -output "Satismeter.xcframework"

Then we add the xcframework to our project and also copy the resources bundle. We need to make sure that the build settings say Embed&Sign and that the resources are also copied to the main app.

But that's not all. We also need to link binary with UIKit and add

-ObjC -l"SatisMeter" -framework "UIKit" to Other Linker Flags of the main project.

Then we need to update Library Search paths to include Satismeter and also SWIFT_INCLUDE_PATHS = "$(PROJECT_DIR)/SatisMeter/SatisMeter.xcframework/ios-arm64 $(PROJECT_DIR)/SatisMeter/SatisMeter.xcframework/ios-x86_64-simulator";

BUT unfortunately such a build was rejected by the Appstore team. It would run and build perfectly, but not good enough for the app store policy makers.

pjechris commented 1 year ago

@mixalturek the solution provided by jsedlacek is just a workaround as it's going to make the whole app running on Rosetta compatibility layer. Which is exactly why we're asking satismeter to rebuild the framework to have native support for M1.

This link explains this better than me: https://susuthapa19961227.medium.com/apple-silicon-and-the-library-incompatibility-problem-for-ios-development-8c2d875283f2

mixalturek commented 1 year ago

Thanks both, I will forward the info to the team. I believe someone will give it a try soon and hopefully fix it for you. I'm primarily BE and partially FE eng., I don't know the word of mobiles at all :-)

Btw, I meant this one https://github.com/satismeter/satismeter-ios/issues/25#issuecomment-1028113618 instead of the Rosetta one.

DelphineGarcia commented 1 year ago

Any news @mixalturek ? We are facing more and more issues using Rosetta and we are currently asking ourselves to stop using Satismeter because of that. We provided you one month ago a full tutorial in this thread, did your engineers have a look and prioritize this topic?

Thanks

jsedlacek commented 1 year ago

@DelphineGarcia, thanks for checking, and sorry about the delays. We hope to have some time for the new build this week.

Update: We got into some issues with the rebuild. We're trying to resolve them and release the new version soon.

DelphineGarcia commented 1 year ago

Hi @jsedlacek , Do you have some news? It is now very urgent since Apple announce in Xcode14.3 release note that "Xcode isnโ€™t supported under Rosetta" (cf https://developer.apple.com/documentation/xcode-release-notes/xcode-14_3-release-notes). So, if a solution is not provided very quickly we will be forced to stop using your library.

pjechris commented 1 year ago

@jsedlacek

I think we gave enough time to Satismeter: the ticket has been opened for 1,5 yea. After that much time I think nothing will be done on your side. Meanwhile apple dropped Rosetta support on Xcode and Bitrise deprecates Intel machines. So we'll just remove the library from our code.

Thank you

jsedlacek commented 1 year ago

@pjechris we have released a new XCFramework build: https://github.com/satismeter/satismeter-ios/tree/main/XCFramework

Could you please check if it resolves the issue?

Thank you.

jsedlacek commented 1 year ago

Fixed with the XCFramework build. https://github.com/satismeter/satismeter-ios/tree/main/XCFramework