While building my Swift application to run on my device, the Embed Pod Frameworks build phase is taking about 40 seconds every time I run the application from Xcode. If I build for the simulator, it does not lag on this step.
The compiler is lagging during custom build phase 2 of 3. If I check Run script only when installing
for the Embed Pod Frameworks, then my application compiles quickly, but I don't think this is a good solution, right?
My project is using multiple Cocoapods, written in both Swift and Objective C with the use_frameworks!
flag set.
Am I doing something wrong, or is this a known issue?
Thanks!
@mrackwitz I think Run script only when installing
might work?
Okay. I wasn't sure if this was going to cause problems later if I've run a pod update or changed any of my development pods and then try to run again. Would it still be considered "installing" if the application was already on the device and we are creating a new build?
I'm not sure, that's something that needs investigating
Last time i researched this behavior, performing a "build" in Xcode will create the app on your computer. performing a "run" will then install it to the device. This should apply to both the simulator and iOS devices.
This doesn't really seem like a fix for the problem though. Skipping the phase is not a good solution, and even so, whenever I run the application, it would still take a long time.
Does anyone from the Cocoapods team have any interest in figuring out why this script is taking so long?
Try adding some logs and see what the slowest part of the process is in the build script?
Thanks @Orta. I'll do that tomorrow
@AnthonyMDev any update? I'm facing the same issue, I tried checking "Run script when installing only" and it works but then I have to manually uncheck and then check them again whenever I run pod install
or update
on my repo, which is too much of a hassle..
@LightD I haven't had time to look more into this recently. I'll try to take another look this week.
I have the same problem with my projects and with every pod I add the whole embedding step gets slower and slower.
@orta I'm still having this same issue. What logs exactly are you asking for? I can't really give you my entire build logs without divulging private information.
I can tell you that I am certain that the longest step in building is the "Embed Pods Framework" step. The logs show multiple steps that look like this for each pod I'm using:
sent 963098 bytes received 92 bytes 1926380.00 bytes/sec
total size is 962632 speedup is 1.00
Code Signing /Users/Anthony/Library/Developer/Xcode/DerivedData/MyApp-gragjdwfnyzchsajwcvrwhxsjwls/Build/Products/Debug-iphoneos/MyApp.app/Frameworks/Alamofire.framework with Identity iPhone Developer: Anthony Miller (7V5726X255)
/usr/bin/codesign --force --sign 8B0F62499B19497B70E49264B781E21F250E83C0 --preserve-metadata=identifier,entitlements /Users/Anthony/Library/Developer/Xcode/DerivedData/MyApp-gragjdwfnyzchsajwcvrwhxsjwls/Build/Products/Debug-iphoneos/MyApp.app/Frameworks/Alamofire.framework
/Users/Anthony/Library/Developer/Xcode/DerivedData/MyApp-gragjdwfnyzchsajwcvrwhxsjwls/Build/Products/Debug-iphoneos/MyApp.app/Frameworks/Alamofire.framework: replacing existing signature
rsync -auv "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib" "/Users/Anthony/Library/Developer/Xcode/DerivedData/MyApp-gragjdwfnyzchsajwcvrwhxsjwls/Build/Products/Debug-iphoneos/MyApp.app/Frameworks"
building file list ... done
It's taking about 4-6 minutes to build. This only occurs when building to run on a device. When I run in the simulator, it builds quickly.
@AnthonyMDev: You may try for now cocoapods-native-integration, but it is a very experimental plugin. After #3550 is merged, we will very likely pickup this behavior in CocoaPods as default integration strategy and fall only back to the script, for scenarios where it is needed.
Still we should further investigate how we can optimize the script. We also may want to set the input and output files appropriately so that the caching is applied and Xcode correctly recognizes when the script must be re-run. Contributions are welcome.
@LightD: For now one other solution would be to check "Run script when installing only" and add a post_install
hook to your Podfile, where you delete the cached build artifacts (a la the relevant DerivedData
subdirectory, check your Xcode settings to see where they are placed), so you don't need to take care of triggering the script by unchecking the checkbox.
@mrackwitz Thanks so much for the update. If this is on the way, then I'll happily wait. It's not causing me to be unable to do any work, I just wanted the contributors to be aware of the issue.
@mrackwitz Is there any way to integrate some build time logs automatically with cocoapods? This way, we'll be able to keep track of the time it takes to build and see if the build times improve or not with new releases
@mrackwitz can you please explain a bit more on how to implement the post_install
hook to the Podfile? I've been searching, and couldn't really find anything that explains how do I get a handle to the derived data directory from the project name (in my case, derived data is relative in every project). Highly appreciated!
@LightD I was really just thinking about something like:
require "FileUtils"
post_install do
FileUtils.rm_rf "DerivedData"
end
well.. that worked actually.. but I've noticed that it happens waaaaaay faster on the latest beta version.. meaning, I'm leaving the scripts on (so they're executing evertim), and the app is compiling very very quickly, I don't even need the post_install
hook anymore.. so basically the latest beta should fix this problem.. though this needs more confirmation and testing..
I have the same problem that this build script takes ages for me every time I build/run the project
Same here, it seems to be related to the code-signing of each frameworks. Any ideas?
I added a new env variable you can add to your build settings as a user defined setting or to your xcconfigs to help speed things up here. Checkout the CHANGELOG for 1.2.0.beta.1 for more details.
I had the same problem. When compiling for the simulator was fast, but when trying to compile for the device, it was very slow, it took about 30 minutes.
For some reason Mac OS X replicated my certificates more than 2000 times, I deleted the duplicate certificates on the Keychain and everything went back up and running fast.
Thanks @ajunior84 you've made me win a lot of time and ressources.
@ajunior84 You saved me hours a day! Thanks!
Now I wonder how much other stuff got messed up in the update??
Hmm, I don't see any (or many) duplicate certificates but... I have this problem where the "embedding" task takes like 30-60 seconds. "Run script only when installing" solves the problem but then occasionally I can't build without cleaning.
At some point the Keychain Access made it so that you have to reveal expired certificates through a menu option, so make sure to show expired certs when hunting down dups.
@benasher44 no dice. I don't see many additional ones. plus why would it consider those anyway if they're expired? :D
It might still have to inspect them to know that they're expired, which would add time.
Read this if you want to learn more about the code signing expectations in regards to certificates: https://pewpewthespells.com/blog/migrating_code_signing.html#building-for-development-xcode-7
Check the size of your keychain file, if it is extremely large that would cause the command that goes to retrieve the signing identities to take a long time.
Is there any way to integrate some build time logs automatically with cocoapods? This way, we'll be able to keep track of the time it takes to build and see if the build times improve or not with new releases
Just to follow up on the above question in case someone was wondering and hadn't found the answer elsewhere...
In terminal: defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
You'll then see a time appended to the build message at the top of Xcode's window:
@entreprenik2 this sounds like a good candidate for a CocoaPods plugin!
@AnthonyMDev I am removing you from the repo temporarily to stop the spamming.
Most helpful comment
I had the same problem. When compiling for the simulator was fast, but when trying to compile for the device, it was very slow, it took about 30 minutes.
For some reason Mac OS X replicated my certificates more than 2000 times, I deleted the duplicate certificates on the Keychain and everything went back up and running fast.
http://stackoverflow.com/a/40298722/3043036