Why files from pod were added to my coverage report? - xcode

I just added Firebase pod and run Tests again:
Why there are firebase files? This is completely different target...

You need to add following line in your podfile in post_install
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
This will cause setting code coverage for each pod to false, so any of your pods will NOT be visible in code coverage of your app.

Solution: Set the CLANG_ENABLE_CODE_COVERAGE flag in the build settings in your podfile
Unfortunately, no more changes are accepted for the existing solution, so here is the complete solution with the complete post-install phase code.
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
end
end

Related

what should I do to change the MACOSX_DEPLOYMENT_TARGET when build flutter macos app

I am building flutter(v3.0.4) macos app in macOS(v12.4 M1 chip) using this command:
~/fvm/versions/3.0.4/bin/flutter build macos --release
shows error like this:
➜ macos git:(main) ✗ ~/fvm/versions/3.0.4/bin/flutter build macos --release --no-tree-shake-icons
Changing current working directory to: /Users/xiaoqiangjiang/source/reddwarf/frontend/tik
💪 Building with sound null safety 💪
Running pod install... 668ms
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006000-001248980AE2801E }
{ platform:macOS, arch:x86_64, id:00006000-001248980AE2801E }
/Users/xiaoqiangjiang/source/reddwarf/frontend/tik/macos/Pods/Pods.xcodeproj: warning: The macOS deployment target 'MACOSX_DEPLOYMENT_TARGET' is set to 10.6, but the range of supported deployment target versions is 10.9 to 12.3.99. (in target 'FMDB' from project 'Pods')
Building macOS application...
I have already change the Pods and Runner deployment target to 10.11. what should I do to change the MACOSX_DEPLOYMENT_TARGET version? this is the macos podfile:
platform :osx, '10.11'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_macos_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!
flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
end
end
this is the Pods macOS deployment config:
I have already tried to clean the build and rebuild the macos app but still could not work as expect.
Went into my macos/Podfile and replaced the post_install method that looked like so…
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
end
end
to look like so instead.
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.15'
end
end
end
source:
https://levelup.gitconnected.com/how-to-fix-your-flutter-macos-target-mismatch-bc55424b7c77
Hope it helps!
Open the macos folder in Xcode and select Pods in the project navigator. Choose the framework target and select the General tab.
Change this Deployment Target in the pods and save the changes that will resolve that issue
After hours looking for a solution, found it.
Need to change at 2 places but into the very same file.
The file is macos/Runner.xcworkspace
Reveal it in Finder, and open with XCode.
1st change in the file:
Runner > General > Minimum Deployment.
Set to minimum in the list or desired (in my case 10.13)
2nd change in the file:
Flutter Assemble > Build Settings > macOS Deployment Target.
Set to the same as before (in my case 10.13)
To switch to the Flutter Assemble, use the submenu below Runner. This was my confusion. The 2 changes need to be made in the very same file and only select Runner or Flutter Assemble with the upper menu under Runner.
See the following video with details too
https://youtu.be/iqGHugqyDiM
Hope this can help.
Attached 2 photos.
In xcode select the target then select build settings. Make sure it displays the combined options. Check valid architecture. Remove architecture which you arent using.
Also please take a back up of yhe project and run
pod install --repo-update

How to delete a scheme in CocoaPods post_install hook

How does one delete a scheme created by CocoaPods in the post_install hook? It is a little convoluted, but this scheme is breaking Carthage builds for my SwiftMessages library.
According to this thread, deleting schemes is possible. However, I've looked through the CocoaPods reference and don't see a way to do it.
Update
Following Thiago Cruz's suggestion, I added the following post install hook to my project. Keeping it simple, I just blew away all of the user and shared data in the pods project.
post_install do |installer|
# Blow away schemes – the schemes created by CocoaPods break Carthage builds
# because they incluede a SwiftMessages framework that Carthage picks
# over the main SwiftMessages framework. The SwiftMessages framework that gets
# picked is configured for an app extension and doesn't work correctly in an app.
File.directory?(path)
[
"#{installer.sandbox.root}/Pods.xcodeproj/xcuserdata",
"#{installer.sandbox.root}/Pods.xcodeproj/xcshareddata"
].each { |path|
if File.directory?(path)
FileUtils.remove_dir(path)
end
}
end
In addition to this, I had to open the pods project and disable "Autocreate schemes" in the scheme management dialog. It's worth noting that pod install doesn't revert this setting.
Not sure which .xcscheme files you want to delete but in a post_install hook you have access to the root of your project and also the /Pods root. You could glob your way to the file and manually delete it.
post_install do |installer|
puts "#{installer.config.installation_root}"
puts "#{installer.sandbox.root}"
end

Why is Cocoapods 1.8.3 adding APPLICATION_EXTENSION_API_ONLY to the Target Support xcconfig file?

We have used Cocoapods in our project for a long time. Ever since 1.8.3, it is adding APPLICATION_EXTENSION_API_ONLY to one of our private pod's Pods/Target Support Files/*/*.xcconfig files, and this, in turn, is causing the build to fail.
As a workaround, we are removing that line, and things are working again.
I would like to fix this issue for good, and would like to know what precisely makes cocoapods add this flag, and what we need to make the project work again.
The pod in question is supposed to be used in extensions, this is true. It does contain conditional compilation (#ifndef TARGET_IS_EXTENSION) to exclude the code that should not go into extensions.
What are we doing wrong?
Instead of doing it manually, you can do it automatically after a pod install with a post_install hook by adding the following to the bottom of your Podfile.
(Below is a template that might need a few tweaks depending on project)
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
if target.name.include?(“CUSTOM_POD”). // or remove if statement to delete/set value for all pods
config.build_settings.delete('APPLICATION_EXTENSION_API_ONLY')
//OR
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO' //or 'YES'
end
end
end

How to fix "Bus error 10" after update to Xcode 10.2

I updated Xcode to new stable 10.2v. I tried to build my project and it was successful. When I'm trying to archive the project (workspace), I'm getting errors like on screenshot below:
What I've tried so far:
Update cocoa pods to latest version -> COCOAPODS: 1.7.0.beta.3
Clean DeliveredData folder
Reinstall Xcode
Remove repository, clone it again and install pods
Totally remove all pods from project and add them back
Temporary Workaround
For me it was only the Cache framework. Until they have fixed it, you can manually set SWIFT_OPTIMIZATION_LEVEL to -Onone for the configuration you want to use for archiving.
CocoaPods
You could even use your Podfile if you don't want Cococapods to overwrite the settings every time you run pod install
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == 'Cache'
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
end
end
end
end
Note that this is specifically checking for the Cache framework. If you have problems with other frameworks you might want to change or extend this condition.
While Lukas' answer of disabling optimization on the Cache pod works, I followed Alex's link to the issue in their GitHub repo and found there is an open pull request with a pretty simple code change that fixes it. I unlocked the file and made the change locally.
Here's the PR: https://github.com/hyperoslo/Cache/pull/236
Apply this diff: https://github.com/hyperoslo/Cache/pull/236/commits/560f00a9a9549db161ca70d96eed74fc580b03e3#diff-9e53dc1370d4f7c9cdaaa103d26ff096
Which, to repeat here, is in the file MD5.swift change the safe_add function to be:
func safe_add(_ x: Int32, _ y: Int32) -> Int32 {
return x &+ y
}
(Disclaimer: I do not claim to know the correctness of the change, but it seems the delay merging the PR is due to figuring out who is currently maintaining the repo.)
The answer is here: https://github.com/hyperoslo/Cache/issues/238
We are waiting for the owners of this repo to make any sign of life...

Hook in Podfile to edit my project file

I want to fix Cocoapods bug, when it adds Embed Pods Frameworks build phase for Extension targets. These phases are not needed there.
https://github.com/CocoaPods/CocoaPods/issues/4203
I wrote script to remove it
puts "Deleting not needed phases…"
project_path = "Keyboard.xcodeproj"
project = Xcodeproj::Project.open(project_path)
project.targets.each do |target|
if target.name.include?("Extension")
phase = target.shell_script_build_phases.find { |bp| bp.name == 'Embed Pods Frameworks' }
if !phase.nil?
puts "Deleting Embed Pods Frameworks phase…"
target.build_phases.delete(phase)
end
end
end
project.save
I can run this script after pod install manually, but I want to add it to Podfile somehow. It doesn't work in post_install hook
post_install do |installer|
...
end
because UserProjectIntegrator.integrate! is called after post_install and it overrides my changes.
Is there any way to integrate this script in Podfile?
The short answer is No.
The long answer:
From the output of pod install --verbose, the build phase Embed Pods Frameworks is added in the Integrating client project which runs after the post_install step in the Podfile.
This is why you should execute this script separately after the pod install finished running.

Resources