Using the AWS SDK for iOS with Third Party Frameworks
Version 2 of the AWS Mobile SDK
- This article and sample apply to Version 1 of the AWS Mobile SDK. If you are building new apps, we recommend you use Version 2. For details, please visit the AWS Mobile SDK page.
- This content is being maintained for historical reference.
When you are using the AWS SDK for iOS and other frameworks in your project, you may encounter a
duplicate symbol error when your project fails to compile. The SDK for iOS is designed to be compatible with any properly packaged framework for iOS, but depending on the configuration of your project or included libraries, you may still encounter this error. In this post, I’ll discuss a common reason for this error and a procedure to correct it.
What causes the duplicate symbol error?
When you encounter the
duplicate symbol error with the third party libraries included in the SDK for iOS, check the flags under Build Settings > Other Linker Flags. If you see some of these three flags, this is likely the source of the error:
-ObjC flag is used to load Objective-C objects including categories from static libraries, and due to a linker bug in the older version of Xcode mentioned in this technical Q&A, you have to use
-force_load flags to properly load categories under certain situations. However, a side effect of this workaround is that it results in the
duplicate symbol error.
In short, Xcode is usually smart enough to prevent a
duplicate symbol error, but a workaround for a linker bug that existed in the old version of Xcode impairs Xcode’s ability to auto-resolve this error.
1. Remove -all_load and -force_load
When you encounter this issue, first get the latest version of Xcode without the aforementioned bug, if possible. Then remove the
-all_load flag and all of the
-force_load flags under Build Settings > Other Linker Flags. You should clean up your project and rebuild it. The error should go away. If the
duplicate symbol error didn’t go away, or you get the
unrecognized selector sent to instance error message in the runtime, the next section details how to solve this.
2. Remove -ObjC and use -force_load
Make sure you’ve removed the
-all_load flags and use
-force_load flag to forcefully load categories from the third party frameworks you use. Here is an example
-force_load flag usage with the Facebook SDK:
Other Linker Flags: -force_load $(SOURCE_ROOT)/FacebookSDK.framework/Versions/A/FacebookSDK
When you clean up and rebuild your project, the
unrecognized selector sent to instance error message should go away. Do not use the
-force_load flag for the AWS SDK for iOS; it may result in the
duplicate symbol error.
Please leave a comment below if you still have issues with third party frameworks after following this procedure.