How can I add post_install configurations to an existing podfile that already has a post_install section? I need to add a line to fix a build clang ld linker error to debug-iphonesimulator myapp.debug.dylib file.
I can't do it manually because using cordova cordova build ios wipes out the manual podfile edits on every build. I am looking at writing a hook script but the examples I see look like it's placing a new/2nd post_install section at the bottom of the podfile which would error out because (from my understanding) the podfile can only have one post_install section.
My current podfile:
# DO NOT MODIFY -- auto-generated by Apache Cordova
source 'https://cdn.cocoapods.org/'
platform :ios, '13.0'
use_frameworks!
target 'myApp' do
project 'myApp.xcodeproj'
pod 'FirebaseCore', '11.8.0'
pod 'FirebaseCoreExtension', '11.8.0'
pod 'FirebaseAuth', '11.8.1'
pod 'FirebaseAnalytics', '11.8.0'
pod 'FirebaseMessaging', '11.8.0'
pod 'FirebasePerformance', '11.8.0'
pod 'FirebaseRemoteConfig', '11.8.0'
pod 'FirebaseInAppMessaging', '11.8.0-beta'
pod 'FirebaseFirestore', '11.8.0'
pod 'FirebaseCrashlytics', '11.8.0'
pod 'FirebaseFunctions', '11.8.0'
pod 'FirebaseInstallations', '11.8.0'
pod 'GoogleSignIn', '7.1.0'
pod 'GoogleTagManager', '8.0.0'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf-with-dsym'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
end
end
end
end
I need to add this one line: config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64' directly under the target.build_configurations.each do |config| section.
The script I am evaluating would be placed in the project root/hooks directory and then in my config.xml file a <hook ...> reference to that script:
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { isFile } = require('cordova-common').FileHelpers;
// This hook is designed to be run as an after_prepare hook.
// It will append custom content to the end of the iOS Podfile.
module.exports = function(context) {
console.log('Running after_prepare hook to modify Podfile...');
const platformRoot = path.join(context.opts.projectRoot, 'platforms/ios');
const podfilePath = path.join(platformRoot, 'Podfile');
if (!isFile(podfilePath)) {
console.log('Podfile not found, skipping modification.');
return;
}
let podfileContent = fs.readFileSync(podfilePath, 'utf-8');
// Define your custom Podfile additions here.
// This example adds a post_install hook to set specific compiler flags.
const customContent = `
# Custom post_install hook added by a Cordova hook
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# NEED TO ADD THIS LINE TO FIX clang ld linker errors for simulators
config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
end
end
end
`;
// Append the custom content to the existing Podfile content
podfileContent += customContent;
// Write the modified content back to the Podfile
fs.writeFileSync(podfilePath, podfileContent, 'utf-8');
console.log('Podfile modified successfully.');