|
| 1 | +require 'xcodeproj' |
| 2 | + |
| 3 | +# Initialize project |
| 4 | +project_path = 'iosApp.xcodeproj' |
| 5 | +project = Xcodeproj::Project.new(project_path) |
| 6 | + |
| 7 | +# Set deployment target to iOS 16.0 project-wide |
| 8 | +project.build_configurations.each do |config| |
| 9 | + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' |
| 10 | +end |
| 11 | + |
| 12 | +# Create group for source files (maps to the iosApp directory) |
| 13 | +group = project.main_group.new_group('iosApp', 'iosApp') |
| 14 | + |
| 15 | +# Reference source files inside the group |
| 16 | +app_delegate_ref = group.new_file('AppDelegate.swift') |
| 17 | +sample_list_ref = group.new_file('SampleListViewController.swift') |
| 18 | +secrets_ref = group.new_file('DeveloperSecrets.swift') |
| 19 | +info_plist_ref = group.new_file('Info.plist') |
| 20 | + |
| 21 | +# Create target |
| 22 | +target = project.new_target(:application, 'iosApp', :ios, '16.0') |
| 23 | + |
| 24 | +# Configure target settings |
| 25 | +target.build_configurations.each do |config| |
| 26 | + config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'com.google.maps.android.compose.iosApp' |
| 27 | + config.build_settings['INFOPLIST_FILE'] = 'iosApp/Info.plist' |
| 28 | + config.build_settings['SWIFT_VERSION'] = '5.0' |
| 29 | + config.build_settings['SDKROOT'] = 'iphoneos' |
| 30 | + config.build_settings['TARGETED_DEVICE_FAMILY'] = '1,2' |
| 31 | + config.build_settings['CODE_SIGNING_REQUIRED'] = 'NO' |
| 32 | + config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' |
| 33 | + config.build_settings['AD_HOC_CODE_SIGNING_ALLOWED'] = 'YES' |
| 34 | +end |
| 35 | + |
| 36 | +# Add a Build Phase Run Script to populate secrets before compilation |
| 37 | +populate_secrets_phase = target.new_shell_script_build_phase('Populate Secrets') |
| 38 | +populate_secrets_phase.shell_script = <<-SHELL |
| 39 | +SECRETS_PATH="${PROJECT_DIR}/../secrets.properties" |
| 40 | +OUTPUT_FILE="${SRCROOT}/iosApp/DeveloperSecrets.swift" |
| 41 | +
|
| 42 | +API_KEY="YOUR_API_KEY" |
| 43 | +
|
| 44 | +if [ -f "$SECRETS_PATH" ]; then |
| 45 | + EXTRACTED_KEY=$(grep -E "^MAPS_API_KEY=" "$SECRETS_PATH" | cut -d'=' -f2 | tr -d '"' | tr -d "'") |
| 46 | + if [ ! -z "$EXTRACTED_KEY" ]; then |
| 47 | + API_KEY="$EXTRACTED_KEY" |
| 48 | + fi |
| 49 | +fi |
| 50 | +
|
| 51 | +cat <<EOF > "$OUTPUT_FILE" |
| 52 | +// Generated file. Do not commit or modify. |
| 53 | +struct DeveloperSecrets { |
| 54 | + static let mapsApiKey = "$API_KEY" |
| 55 | +} |
| 56 | +EOF |
| 57 | +SHELL |
| 58 | + |
| 59 | +# Move the secrets phase to the very beginning of target build phases |
| 60 | +target.build_phases.delete(populate_secrets_phase) |
| 61 | +target.build_phases.insert(0, populate_secrets_phase) |
| 62 | + |
| 63 | +# Add files to their respective build phases |
| 64 | +source_build_phase = target.source_build_phase |
| 65 | +source_build_phase.add_file_reference(app_delegate_ref) |
| 66 | +source_build_phase.add_file_reference(sample_list_ref) |
| 67 | +source_build_phase.add_file_reference(secrets_ref) |
| 68 | + |
| 69 | +project.save |
| 70 | +puts "Xcode project created successfully!" |
| 71 | + |
0 commit comments