Importing CommonCrypto in a Swift framework
Solution 1
I found a GitHub project that successfully uses CommonCrypto in a Swift framework: SHA256-Swift. Also, this article about the same problem with sqlite3 was useful.
Based on the above, the steps are:
1) Create a CommonCrypto
directory inside the project directory. Within, create a module.map
file. The module map will allow us to use the CommonCrypto library as a module within Swift. Its contents are:
module CommonCrypto [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/usr/include/CommonCrypto/CommonCrypto.h"
link "CommonCrypto"
export *
}
2) In Build Settings, within Swift Compiler - Search Paths, add the CommonCrypto
directory to Import Paths (SWIFT_INCLUDE_PATHS
).
3) Finally, import CommonCrypto inside your Swift files as any other modules. For example:
import CommonCrypto
extension String {
func hnk_MD5String() -> String {
if let data = self.dataUsingEncoding(NSUTF8StringEncoding)
{
let result = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH))
let resultBytes = UnsafeMutablePointer<CUnsignedChar>(result.mutableBytes)
CC_MD5(data.bytes, CC_LONG(data.length), resultBytes)
let resultEnumerator = UnsafeBufferPointer<CUnsignedChar>(start: resultBytes, length: result.length)
let MD5 = NSMutableString()
for c in resultEnumerator {
MD5.appendFormat("%02x", c)
}
return MD5
}
return ""
}
}
Limitations
Using the custom framework in another project fails at compile time with the error missing required module 'CommonCrypto'
. This is because the CommonCrypto module does not appear to be included with the custom framework. A workaround is to repeat step 2 (setting Import Paths
) in the project that uses the framework.
The module map is not platform independent (it currently points to a specific platform, the iOS 8 Simulator). I don't know how to make the header path relative to the current platform.
Updates for iOS 8 <= We should remove the line link "CommonCrypto", to get the successful compilation.
UPDATE / EDIT
I kept getting the following build error:
ld: library not found for -lCommonCrypto for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Unless I removed the line link "CommonCrypto"
from the module.map
file I created. Once I removed this line it built ok.
Solution 2
Something a little simpler and more robust is to create an Aggregate target called "CommonCryptoModuleMap" with a Run Script phase to generate the module map automatically and with the correct Xcode/SDK path:
The Run Script phase should contain this bash:
# This if-statement means we'll only run the main script if the CommonCryptoModuleMap directory doesn't exist
# Because otherwise the rest of the script causes a full recompile for anything where CommonCrypto is a dependency
# Do a "Clean Build Folder" to remove this directory and trigger the rest of the script to run
if [ -d "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap" ]; then
echo "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap directory already exists, so skipping the rest of the script."
exit 0
fi
mkdir -p "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap"
cat <<EOF > "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap/module.modulemap"
module CommonCrypto [system] {
header "${SDKROOT}/usr/include/CommonCrypto/CommonCrypto.h"
export *
}
EOF
Using shell code and ${SDKROOT}
means you don't have to hard code the Xcode.app path which can vary system-to-system, especially if you use xcode-select
to switch to a beta version, or are building on a CI server where multiple versions are installed in non-standard locations. You also don't need to hard code the SDK so this should work for iOS, macOS, etc. You also don't need to have anything sitting in your project's source directory.
After creating this target, make your library/framework depend on it with a Target Dependencies item:
This will ensure the module map is generated before your framework is built.
macOS note: If you're supporting macOS
as well, you'll need to add macosx
to the Supported Platforms
build setting on the new aggregate target you just created, otherwise it won't put the module map in the correct Debug
derived data folder with the rest of the framework products.
Next, add the module map's parent directory, ${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap
, to the "Import Paths" build setting under the Swift section (SWIFT_INCLUDE_PATHS
):
Remember to add a $(inherited)
line if you have search paths defined at the project or xcconfig level.
That's it, you should now be able to import CommonCrypto
Update for Xcode 10
Xcode 10 now ships with a CommonCrypto module map making this workaround unnecessary. If you would like to support both Xcode 9 and 10 you can do a check in the Run Script phase to see if the module map exists or not, e.g.
COMMON_CRYPTO_DIR="${SDKROOT}/usr/include/CommonCrypto"
if [ -f "${COMMON_CRYPTO_DIR}/module.modulemap" ]
then
echo "CommonCrypto already exists, skipping"
else
# generate the module map, using the original code above
fi
Solution 3
You can actually build a solution that "just works" (no need to copy a module.modulemap and SWIFT_INCLUDE_PATHS
settings over to your project, as required by other solutions here), but it does require you to create a dummy framework/module that you'll import into your framework proper. We can also ensure it works regardless of platform (iphoneos
, iphonesimulator
, or macosx
).
Add a new framework target to your project and name it after the system library, e.g., "CommonCrypto". (You can delete the umbrella header, CommonCrypto.h.)
-
Add a new Configuration Settings File and name it, e.g., "CommonCrypto.xcconfig". (Don't check any of your targets for inclusion.) Populate it with the following:
MODULEMAP_FILE[sdk=iphoneos*] = \ $(SRCROOT)/CommonCrypto/iphoneos.modulemap MODULEMAP_FILE[sdk=iphonesimulator*] = \ $(SRCROOT)/CommonCrypto/iphonesimulator.modulemap MODULEMAP_FILE[sdk=macosx*] = \ $(SRCROOT)/CommonCrypto/macosx.modulemap
-
Create the three referenced module map files, above, and populate them with the following:
-
iphoneos.modulemap
module CommonCrypto [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * }
-
iphonesimulator.modulemap
module CommonCrypto [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * }
-
macosx.modulemap
module CommonCrypto [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * }
(Replace "Xcode.app" with "Xcode-beta.app" if you're running a beta version. Replace
10.11
with your current OS SDK if not running El Capitan.) -
On the Info tab of your project settings, under Configurations, set the Debug and Release configurations of CommonCrypto to CommonCrypto (referencing CommonCrypto.xcconfig).
On your framework target's Build Phases tab, add the CommonCrypto framework to Target Dependencies. Additionally add libcommonCrypto.dylib to the Link Binary With Libraries build phase.
Select CommonCrypto.framework in Products and make sure its Target Membership for your wrapper is set to Optional.
You should now be able to build, run and import CommonCrypto
in your wrapper framework.
For an example, see how SQLite.swift uses a dummy sqlite3.framework.
Solution 4
This answer discusses how to make it work inside a framework, and with Cocoapods and Carthage
🐟 modulemap approach
I use modulemap
in my wrapper around CommonCrypto https://github.com/onmyway133/arcane, https://github.com/onmyway133/Reindeer
For those getting header not found
, please take a look https://github.com/onmyway133/Arcane/issues/4 or run xcode-select --install
-
Make a folder
CCommonCrypto
containingmodule.modulemap
module CCommonCrypto { header "/usr/include/CommonCrypto/CommonCrypto.h" export * }
-
Go to Built Settings -> Import Paths
${SRCROOT}/Sources/CCommonCrypto
🌳 Cocoapods with modulemap approach
-
Here is the podspec https://github.com/onmyway133/Arcane/blob/master/Arcane.podspec
s.source_files = 'Sources/**/*.swift' s.xcconfig = { 'SWIFT_INCLUDE_PATHS' => '$(PODS_ROOT)/CommonCryptoSwift/Sources/CCommonCrypto' } s.preserve_paths = 'Sources/CCommonCrypto/module.modulemap'
Using
module_map
does not work, see https://github.com/CocoaPods/CocoaPods/issues/5271Using Local Development Pod with
path
does not work, see https://github.com/CocoaPods/CocoaPods/issues/809-
That's why you see that my Example Podfile https://github.com/onmyway133/CommonCrypto.swift/blob/master/Example/CommonCryptoSwiftDemo/Podfile points to the git repo
target 'CommonCryptoSwiftDemo' do pod 'CommonCryptoSwift', :git => 'https://github.com/onmyway133/CommonCrypto.swift' end
🐘 public header approach
Ji is a wrapper around libxml2, and it uses public header approach
It has a header file https://github.com/honghaoz/Ji/blob/master/Source/Ji.h with
Target Membership
set toPublic
It has a list of header files for libxml2 https://github.com/honghaoz/Ji/tree/master/Source/Ji-libxml
-
It has Build Settings -> Header Search Paths
$(SDKROOT)/usr/include/libxml2
-
It has Build Settings -> Other Linker Flags
-lxml2
🐏 Cocoapods with public header approach
-
Take a look at the podspec https://github.com/honghaoz/Ji/blob/master/Ji.podspec
s.libraries = "xml2" s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2', 'OTHER_LDFLAGS' => '-lxml2' }
🐝 Interesting related posts
Solution 5
Good news! Swift 4.2 (Xcode 10) finally provides CommonCrypto!
Just add import CommonCrypto
in your swift file.
Related videos on Youtube
hpique
iOS, Android & Mac developer. Founder of Robot Media. @hpique
Updated on August 26, 2020Comments
-
hpique over 3 years
How do you import
CommonCrypto
in a Swift framework for iOS?I understand how to use
CommonCrypto
in a Swift app: You add#import <CommonCrypto/CommonCrypto.h>
to the bridging header. However, Swift frameworks don't support bridging headers. The documentation says:You can import external frameworks that have a pure Objective-C codebase, a pure Swift codebase, or a mixed-language codebase. The process for importing an external framework is the same whether the framework is written in a single language or contains files from both languages. When you import an external framework, make sure the Defines Module build setting for the framework you’re importing is set to Yes.
You can import a framework into any Swift file within a different target using the following syntax:
import FrameworkName
Unfortunately, import
CommonCrypto
doesn't work. Neither does adding#import <CommonCrypto/CommonCrypto.h>
to the umbrella header.-
rmaddy almost 10 yearsCommonCrypto is a C-based framework, not an Objective-C framework.
-
hpique almost 10 years@rmaddy Objective-C is a C superset. Are you saying we can't use CommonCrypto from Swift?
-
hpique almost 10 years@rmaddy I just managed to get CommonCrypto working by using module maps. I will polish the solution and post it later today.
-
Marcin over 9 yearsif you find it convenience, and what you looking for is already implemented, you can give a try to CryptoSwift
-
eyeballz over 8 yearsApple just open sourced CommonCrypto. Maybe we can get it running if we have the sources.
-
Roy Falk over 6 yearsIs there a timeframe for a real solution, rather than one of these hacks. This and ABI compatibility make me think Apple doesn't get it or just doesn't care. I'm seriously thinking of porting my frameworks back to Objective C. I don't like the language, but at least I don't have to relearn the String class every release.
-
Martin Berger about 6 yearsIn my framework i have created Objective-C class named MyProjectCrypto, and in that class included CommonCrypto. I use this class in my Umbrella Header, and in swift source files. So this is just Objective-C Facade around C framework.
-
-
zaph over 9 yearsGee, Apple sure want's to make things difficult. Would it kill the Swifties to just let us import files/frameworks without having to go through all this BS?
-
danimal over 9 yearsThis is infuriating since the
$SDKROOT
variable is supposed to allow you platform agnostic paths, but I have no idea how to get to that in Swift. -
Saorikido over 9 yearsI got a compile error, var result:CCCryptorStatus = CCCrypt( kCCEncrypt, kCCAlgorithm3DES, kCCOptionPKCS7Padding | kCCOptionECBMode, key, kCCKeySize3DES ..,
-
Saorikido over 9 yearsI got a compile error, it occurred the first line, var result:CCCryptorStatus = CCCrypt(kCCEncrypt... it tells 'Int' is not convertible to CCOperation. do you know how to solve it?
-
Garrett over 9 yearsI've been trying this with
NMSSH
, but I keep gettingld: library not found for -lNMSSH for architecture arm64
as well as for armv7. I can't figure out why. -
Bodey Baker over 9 years@Zaph, your statement could be rephrased as: Gee C makes it really hard to avoid security holes and bugs.
-
zaph over 9 years@porcoesphino Ah, Swift would have made Heartbleed impossible? Eliminate poor crypto practices?
UnsafeBufferPointer
is unnecessary? It is not the language, it is the programmers. Even the goto fail bug was mainly due to violating the DRY principle. Heaven help the person saying that "The Emperor has no clothes." -
Bodey Baker over 9 yearsKkk. You know my comment wasn't saying Swift was perfect. I've never coded in Swift but have coded a lot in C. Still it's easy to see that C allows developers to easily make mistakes that can be abused. Swift closes some of those holes. Apple likes closing holes (and pushing their agenda). It's annoying but hardly a surprise. What do they have to gain from doing what you're complaining about? They do have things to lose.
-
A . Radej over 9 yearsI'm wondering if Swift 1.2 allows an easier mechanism for doing this?
-
gorgi93 about 9 yearsyour method returns error: using bridging headers with framework targets is unsupported
-
Charles A. about 9 years@gorgi93 You can't use a bridging header in a framework target, as the error suggests. The only option is to put it in the main framework header file, unfortunately.
-
stannie about 9 yearsWorks for me without step (5). With it I get a build error:
ld: cannot link directly with /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.2.sdk/usr/lib/system/libcommonCrypto.dylib. Link against the umbrella framework 'System.framework' instead. for architecture x86_64
-
stephencelis about 9 years@stannie I've updated the instructions to remove step 5 (it was unnecessary) and also account for a potential app store rejection around embedded sub-frameworks (see github.com/stephencelis/SQLite.swift/issues/88).
-
Sam Soffes about 9 yearsExcellent! Used this to make github.com/soffes/Crypto I didn't have to link
System.framework
though. It's worth noting, you have to make a separate wrapper framework for Mac and iOS if your framework is cross platform. -
Teo Sartori almost 9 yearsFor me it didn't work until I removed the
link "CommonCrypto"
from the module.map file. -
dogsgod almost 9 yearsAmazing. Step 5 is not working for me either, but without - like a charm! I owe you a beer or two!
-
A . Radej almost 9 yearsStill necessary in Xcode 7 beta 5. However, note that it appears to be no longer necessary to include the setting in the project using the framework.
-
hola over 8 yearsHow or where do people find out stuff like this?
-
Teo Sartori over 8 yearsJust a note make it clear that you need to select Objective-C as language in step 1. This is easily overlooked. Also, perhaps because I didn't have a .dylib, I needed to add the .framework in step 5.
-
Vasily over 8 yearsGetting "no such module CommonCrypto" always… Also doesn't have .dylib in step 5. XCode 7.2
-
A . Radej over 8 years@hpique This solution appears to no longer work in Xcode 7.3 beta 1. Struggling to find another solution. See: stackoverflow.com/questions/34772239/…
-
Danny Bravo over 8 yearsThis solution works on our umbrella project but the tests this are failing with a "No such module: 'CommonCrypto'" error.
-
Anton Tropashko over 8 yearsthis is horrible. I have a zoo of Xcodes each broken in a different ways and having the absolute paths to the headers all over the place is puke invoking. Something is going awfully wrong in cupertino, or at least with whoever is in charge of this modulemap mess
-
Anton Tropashko over 8 years7.2.1 rolled out on feb 2nd and release notes says "The Swift compiler is now stricter about including non-modular header files. Debugging a Swift target requires that frameworks be properly modular, meaning all of the publicly-imported headers are either accounted for in the framework's umbrella header, imported from another modular framework, or listed explicitly in a custom module.modulemap file (advanced users only)." this is IMNSHO not for advanced users, this is a feature geared towards true masochists
-
miken.mkndev about 8 yearsIf you had actually red the title of this thread you would have seen that the guy is wanting to import the CommonCrypto library into a Swift framework. You cannot use bridging headers in frameworks, and you cannot import the CommonCrypto framework into the umbrella header.
-
Reda Lemeden about 8 yearsNote that if you are using CI this solution will easily break due to the hardcoded header paths. I'm still trying to figure out a workaround.
-
Nikita Kukushkin about 8 yearsCan anyone confirm this working on Xcode 7.3? This solution stopped working for me after the update.
-
Nikita Kukushkin about 8 yearsCorrenction: it's working fine when I build for simulator, but fails @ linking when I build for an iOS 9.3 device with "ld: library not found for -lCommonCrypto for architecture arm64"
-
Oded Regev about 8 yearsXcode 7.3 - Apple made some changes to CommonCrypto and now this solution doesn't work when running on real device. Anyone knows how to fix this? I get an error related to Bitcode
-
Nikita Kukushkin about 8 years@OdedRegev I just followed the instructions in this answer and everything works for me now.
-
Adam Carter about 8 yearsTrying to build with this method causes build errors using Xcode 7.3
-
Simon Guerout about 8 yearsCan't make it work at all, it won't build except when running a test on my machine.
-
Oded Regev about 8 yearsI get the following error when running on real device: "CommonCrypto does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64"
-
picciano almost 8 yearsJust to clarify, as of June 6, 2016, I am able to get this working on both the device and simulator with the latest Xcode release following steps 1–4. Steps 5 & 6 were not needed for me. I am producing a Universal (device and simulator) framework.
-
eyeballz almost 8 yearsUpdate: I asked some Apple engineers yesterday and they said modulemap is the way to go.
-
Roy Falk almost 8 yearsNote that you must download the command line tools or none of the above will work. xcode-select --install will solve the problem.
-
kailoon almost 8 yearsNot sure if this is a good solution, but I was able to build and run on my device. stackoverflow.com/questions/38800435/…
-
Benjohn over 7 yearsIs it possible to replace at least some of
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/
in the.modulemap
with something semantic, such as$SDKROOT
, or something? It seems a bit bonkers that there's not way to provide a relative path as of Xcode 8. Thanks! -
DShah over 7 yearsI am using Xcode 8.2.1, and I do not find "libcommonCrypto.dylib" mentioned in step 5. What is the alternative to that?
-
jamil ahmed over 7 yearsI can't hardcode a specific version of OSX in the path. Other people may checkout the code and have a different version of the OS. Is there an environment variable for that stuff?
-
Matthew Seaman over 7 years@i_am_jorf You should be able to use "MacOSX.sdk" instead of "MacOSX10.11.sdk" in the path.
-
codingFriend1 about 7 yearsI found this to compile reliably and it is plain simple. Does the application using the framework need to link to anything special, or is CommonCrypto always available?
-
Rob Napier about 7 yearsI think
Security.framework
is automatically linked (it's be a little while since a started a new project). If you get errors, that's the framework to link. -
Georg about 7 yearsIt's working for me but out of curiosity... you only have a link to the simulator sdk but it's working on my device?!? how? :)
-
jamil ahmed almost 7 years@HuseinBehboodiRad because you can't use a bridging header in a swift framework.
-
Abdullah Saeed almost 7 yearsThis answer should be on top. Simple and elegant
-
Raphael almost 7 yearsThis works very smoothly, and even allows you to keep internals internal (
NSData+NSDataEncryptionExtension.h
doesn't have to be public). -
fatuous.logic almost 7 yearsLate to the game on this one - but this should be the chosen answer. It's simple and is easier for other dev's working on the same project to see the requirement.
-
Natalia almost 7 yearsWow! To my surprise, the header path from the top approach (creating the module.modulemap file) worked great when previously modulemap files had been causing lots of issues. I had been struggling with this for a while using a module.modulemap file with an absolute path to
/CommonCrypto/CommonCrypto.h
withinApplications/XCode.app/Contents/Developer/Platforms/iPhoneOS....
, which required manual modification for people who renamed XCode. Switching that line to look at"/usr/include/CommonCrypto/CommonCrypto.h"
seems to work fine for a team with several XCode versions. Thank you so much! -
Klein Mioke almost 7 yearsIm creating a pod, I set the SWIFT_INCLUDE_PATHS and preserve_paths. When I run
pod lib lint
, but build failed with error: no such module 'CommonCrypto'. How can I deal with it. -
Ravi Kiran almost 7 yearsIf I do this in my .framework , should I have to do the same in the projects where I include this framework?
-
richever almost 7 yearsThis solves the problem of using a C library within a framework, but the path generated with the run script is not portable across machines, i.e. developer laptop, CI build machine etc. Including a framework using a module map as mentioned in this solution doesn't seem to work across different machines with different Xcode and SDK paths.
-
richever almost 7 yearsThis does seem like the most simple solution and it works great on one machine, but whenever I use the framework in another framework, or app, on another machine I get the 'missing module' error.
-
Mike Weller almost 7 yearsThe run script's path is calculated using the correct build variables and I can verify it works in a large team across many different developers, multiple CI servers running versions of Xcode in various different locations. What issue/errors are you seeing?
-
Fomentia over 6 yearsNot related to the problem but I love the use of emoji as bullets! 😊
-
Vanya over 6 years@MikeWeller Hello, I did follow the steps described above, but getting No such module 'CommonCrypto'. I use xCode 9 now. Is there something more with the new version of xCode to make it work? Or I am missing something.
-
Vanya over 6 yearsFound that. Wrong reference for module.
-
Krishnarjun Banoth over 6 years@Vanya did you success with xCode9.
-
Vanya over 6 years@KrishnarjunBanoth Actually I needed to move forward really fast, so I just copied the resulted module into the correct directory. Probably gonna look at that later to fix it. There is some wrong with BUILT_PRODUCTS_DIR which point to incorrect directory. Once I solve that I let know.
-
Krishnarjun Banoth over 6 years@Vanya ok, let me know results of your doing.
-
Ian Dundas over 6 yearsThis worked great, but unfortunately we saw (perhaps obviously, now I think about it) that linking against this Aggregate Build Target in framework targets in our project caused their source to be recompiled from scratch every time when building the main app target. Doh :(
-
HaneTV over 6 years@Vanya : I need to release my (broken) framework urgently and I'm facing the same issue, can you describe the step of "copied the resulted module into the correct directory." ?
-
iwasrobbed over 6 years@IanDundas I updated the code above with a fix for the re-compilation issue as well as a fix for using this on macOS
-
Orkhan Alikhanov over 6 years@onmyway133 Using local development pod works if you replace
$(PODS_ROOT)/CommonCryptoSwift/Sources/CCommonCrypto
with$(PODS_TARGET_SRCROOT)/Sources/CCommonCrypto
.PODS_TARGET_SRCROOT
is set correctly for local pods. -
Ky - over 6 yearsI'm not sure if/when this changed, but for me, this path works. It should work in future releases, too:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/CommonCrypto/CommonCrypto.h
-
Segabond over 6 yearsWarning: Your application will be rejected if you use this method!
-
Nikita Kukushkin over 6 yearsYep, we got rejected as well, very weird, because we were uploading with no problems for several months using this method.
-
Siddharth over 6 yearsThere is so much BS with Apple XCode and Swift, I dont know where to start. Are you serious ? A absolute path in project setttings file, how in earth am I going to get a team to work on this ? They have to chnage the path everytime before they start work ? Really ?
/Applications/Xcode6-Beta5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/usr/include/CommonCrypto/CommonCrypto.h"
-
Abhijeet Barge about 6 yearsI am getting error - "No such module 'CommonCrypto'", I have created framework project and it uses Common crypto. I am installing my framework using cocoapod. I think in my case module map is not generating when use framework in other project using cocoa pod, Any solution?
-
Mike Weller about 6 yearsSurprised I made this mistake originally, but the run script phase might need to use
${TARGET_BUILD_DIR}
since it is generating files for the current target, and in certain environments e.g. while archiving this can cause issues. Looks like Xcode 9.3 (beta) may have introduced changes which cause this to break. The header search path dependency should still use${BUILT_PRODUCTS_DIR}
however. -
Mike Weller about 6 yearsLooks like SWIFT_INCLUDE_PATHS also needs to have the module map's directory as of Xcode 9.3 beta to avoid "missing required module" errors from dependent frameworks
-
Motti Shneor about 6 yearsBut what OS framework should I link against, to use this thing? Unlike others - I have to work with CommonCrypto in an Obj-C project, and that alone breaks on Xcode 9 with MacOS-10.13 SDK
-
Terence about 6 years@MottiShneor Link any OS from 10.9 or above. I am working on same environment and it works fine.
-
Max about 6 yearsHey @MikeWeller. Thanks for the solution. Have you run into any issues with error messages for
missing required architecture
? Looks like it is not being compiled for all of the architectures for some reason. Thanks! -
Motti Shneor about 6 yearsOne possible improvement to your script build-step. Pay attention that you can define 'input files' and 'output files' to the build step, and then you do not need the conditional in the script, and Xcode will manage the need for rebuilding the module map automatically
-
Hassan Shahbazi almost 6 yearsGreat answer, saved my life! Thanks a million
-
Kryštof Matěj almost 6 yearsGreat news! Can you add the link to documentation?
-
mxcl almost 6 yearsI don't have a link to documentation, I discovered this while trying to compile a project where I had one of the workarounds here with Xcode 10. It complained that it could find two
CommonCrypto
modules, thus suspecting Apple now provided I removed my workaround and ’lo! It was true. I tweeted about it and an Apple engineer replied confirming that it was intended. -
Hammad Tariq almost 6 yearsApp store is only showing me 9.4.7 as an available update, how you got Xcode 10?
-
mxcl almost 6 yearsIt's in beta as a trivial Google search would have told you.
-
jjrscott almost 6 yearsSee dvdblk's answer for an improvement that covers usage in CocoaPods.
-
SafeFastExpressive over 5 yearsA little more love for @MikeWeller and his timely update on supporting Xcode 10!
-
Gowtham over 5 yearsCan you provide demo or sample framework project for the same along with the pod spec file?
-
Gowtham over 5 yearsThis works great, but i'm not able to push this framework to pod repo for using through cocoapod. Do you have any solution for that?
-
Baran Emre over 5 yearsYou are awesome! That just saved us a ton of time. Thanks!
-
Mohammad Zaid Pathan over 5 yearsAwesome! Just do
import CommonCrypto
in your swift file. -
COLD ICE over 5 yearsThank you.. That's why I had got a message "redefinition of module 'commoncrypto'" with older projects when updated my xcode to 10.. I tried to figure out what's happening, then I saw your answer
-
Somoy Das Gupta over 5 years@COLDICE How did you solve the redefinition? Did you remove the previous import?
-
COLD ICE over 5 years@SomoyDasGupta yes. Just remove the previous import, and compile it again. In other words, you don't have to do the steps from MikeWeller answer
-
Somoy Das Gupta over 5 yearsthanks @COLDICE. But would it work with the previous iOS versions?
-
COLD ICE over 5 years@SomoyDasGupta yes, I believe so.
-
Lohith Korupolu over 5 yearsAwesome! I think this should be the accepted answer!!
-
Rainer Schwarz over 5 yearsDuplicate of @mxcl's answer: stackoverflow.com/a/50690346/9988514
-
Vyachaslav Gerchicov almost 4 years@dvdblk In my case I have a my own pod which uses third-party pod which uses
CommonCrypto
. Should I fix my pod or should it be fixed in that third-party pod?