Unlinking Google Maps
1. Add snippet to the end of your Podfile
# == Mozio Start ===
# The following snippet removes duplicate Google Maps linkage
# This is required as part of Mozio's setup process
# More info: https://developer.mozio.com/mobile-sdk/ios_unlink_google_maps
PROJECT_ROOT_DIR = File.dirname(File.expand_path(__FILE__))
PODS_DIR = File.join(PROJECT_ROOT_DIR, 'Pods')
PODS_TARGET_SUPPORT_FILES_DIR = File.join(PODS_DIR, 'Target Support Files')
post_install do |installer|
remove_static_framework_duplicate_linkage({'SharedFramework' => ['GoogleMaps']})
end
def remove_static_framework_duplicate_linkage(static_framework_pods)
puts "Removing duplicate linkage of static frameworks"
Dir.glob(File.join(PODS_TARGET_SUPPORT_FILES_DIR, "Pods-*")).each do |path|
pod_target = path.split('-', -1).last
static_framework_pods.each do |target, pods|
next if pod_target == target
frameworks = pods.map { |pod| identify_frameworks(pod) }.flatten
Dir.glob(File.join(path, "*.xcconfig")).each do |xcconfig|
lines = File.readlines(xcconfig)
if other_ldflags_index = lines.find_index { |l| l.start_with?('OTHER_LDFLAGS') }
other_ldflags = lines[other_ldflags_index]
frameworks.each do |framework|
other_ldflags.gsub!("-framework \"#{framework}\"", '')
end
File.open(xcconfig, 'w') do |fd|
fd.write(lines.join)
end
end
end
end
end
end
def identify_frameworks(pod)
frameworks = Dir.glob(File.join(PODS_DIR, pod, "**/*.framework")).map { |path| File.basename(path) }
if frameworks.any?
return frameworks.map { |f| f.split('.framework').first }
end
return pod
end
# == Mozio End ===
2. Add Build Phase to remove GoogleMaps.bundle
This bundle is already located inside our framework so we can safely remove it:
- Select your project.
- Select your target.
- Click the
+
sign and selectNew Run Script Phase
. - Rename the phase
Remove Google Maps bundle
- Add the following code to it:
rm -rf "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleMaps.bundle"
Why is this needed?
There is an issue with Cocoapods when linking static frameworks that are shared between dependencies: Duplicate classes warnings at runtime when multiple targets are contained in the same project. The snippet from above was taken from this comment on that thread.
Without the added snippet and build phase, Google Maps sources and assets are added in both your App and our SDK generating the warning seen next and also increasing your App size unnecessarily:
objc[62446]: Class GMSMapClearcutClient is implement in both /Users/XXX/Library/Developer/Xcode/DerivedData/MozioSDK-chsbavtjlyaaamhmkxz/Build/Products/Debug-iphonesimulator/MozioSDK.framework/MozioSDK (0x110e11ac8) and /Users/XXX/Library/Developer/CoreSimulator/Devices/D38F97B5-0A52-454F-A0A8-5D86C12EEFA7/data/Containers/Bundle/Applications/F26E40A9-FE71-461A-ABCB-26BA838DF424/YourApp.app/YourApp (0x10cd26e78). One of the two will be used. Which one is undefined.