type
status
date
slug
summary
tags
category
icon
password
I was developing an Apple Watch app that uses AES encryption algorithm in OpenSSL. However, the official OpenSSL repository does not provide frameworks for iOS/WatchOS platforms. Therefore, we need to build it ourselves. Fortunately, there is a reliable OpenSSL framework repository available for Apple-related systems. We can simply download the repository and use the script in the repository to build an xcframework.
Assuming that you have embedded the OpenSSL framework in your project, two problems may occur when building your project for watchOS:
1. Build Error - Undefined symbols for architecture arm64
This happens because Xcode 14 adds
arm64
to the Standard Architectures for watchOS.Xcode 13.4.1:
Xcode 14:
Manually settings the Architectures to
arm64_32
and armv7k
instead of using the Standard Archs seems to work for now, but it unknown it will cause problems when watchOS 10.0 will be released, alongside a Watch Series 9 that might not support arm64_32
anymore?For now you can add
arm64
to Excluded Architecture
to avoid the issue. As far as I know, the latest version of Apple Watch (which is Series 8 at present) is not arm64 architecture yet, so you may need to keep an eye out for any updates on this.Reference
2. Crashed on dyld load OpenSSL
The watch app crashed upon launching.
Since the crash occurred with a stack on OpenSSL dyld loading, it's highly likely that there is an issue within the OpenSSL framework.
I found a similar issue on Github:
A openssl repository member mentioned Is getauxval function available on iOS?
Here is the original text
Is
getauxval
function available on iOS? Unfortunately openssl uses probing if getauxval
is not implemented. Probing works by setting SIGILL handler and trying the instruction whether it triggers SIGILL. If that isn't possible to do on iOS, then someone more knowledgeable with iOS and possible devices could suggest some other way how to probe.And the member suggest the issue author, build with
no-asm
,however that will make the crypto algorithms quite slower.To be honest, I really don’t care about the performance between the two algorithms when my app can not launch. I tried the suggestion immediately,here are the workable steps:
- download repository
- modify the file
config/20-ios-tvos-cross.conf
// change the asm parameter from "armv4_asm" to "no-sam" "watchos-cross-armv7k" => { inherit_from => [ "darwin-common", "watchos-cross-base", asm("no-asm") ], cflags => add("-arch armv7k"), perlasm_scheme => "ios32", sys_id => "watchOS", }, // change the asm parameter from "aarch64_asm" to "no-sam" "watchos-cross-arm64_32" => { inherit_from => [ "darwin-common", "watchos-cross-base", asm("no-asm") ], cflags => add("-arch arm64_32"), perlasm_scheme => "ios64", sys_id => "watchOS", }
- execute the script
./
build-libssl.sh
- execute the script
./
create-xcframework.sh
Congratulation! You got the workable OpenSSL framework for WatchOS!