Slide 1

Slide 1 text

xcconfig pitfalls (LT) iOSDC 2017 Sep 17, 2017 Toshihiro Suzuki © Toshihiro Suzuki 2017 1

Slide 2

Slide 2 text

whoami — ླ໦ ढ़༟ (@toshi0383) Toshihiro Suzuki — iOS/tvOS Dev at AbemaTV — Father (5 month) — F1, GT SPORT © Toshihiro Suzuki 2017 2

Slide 3

Slide 3 text

tools and apps https://toshi0383.github.io/LGTM © Toshihiro Suzuki 2017 3

Slide 4

Slide 4 text

Agenda — What's xcconfig and Why would you use it? — Common Pitfails © Toshihiro Suzuki 2017 4

Slide 5

Slide 5 text

What's xcconfig? where you put your build se!ings © Toshihiro Suzuki 2017 5

Slide 6

Slide 6 text

How it looks on Xcode © Toshihiro Suzuki 2017 6

Slide 7

Slide 7 text

How it looks inside xcconfig © Toshihiro Suzuki 2017 7

Slide 8

Slide 8 text

Why? — Easier to review in Pull requests — Refactor using #include — Reusable © Toshihiro Suzuki 2017 8

Slide 9

Slide 9 text

Recommended way to extract — Extract using toshi0383/xcconfig-extractor — Validate using xcodebuild -showBuildSettings © Toshihiro Suzuki 2017 9

Slide 10

Slide 10 text

Let's Do it ! CONFIGURATION =-configuration Debug WORKSPACE =-workspace iOSSingleViewApp.xcworkspace SCHEME =-scheme iOSSingleViewApp OPTIONS=$(CONFIGURATION) $(WORKSPACE) $(SCHEME) xcodebuild -showBuildSettings $(OPTIONS) > before xcconfig-extractor --no-trim-duplicates *.xcodeproj Config/xcconfigs xcodebuild -showBuildSettings $(OPTIONS) > after diff before after © Toshihiro Suzuki 2017 10

Slide 11

Slide 11 text

Sample App © Toshihiro Suzuki 2017 11

Slide 12

Slide 12 text

Result © Toshihiro Suzuki 2017 12

Slide 13

Slide 13 text

$(inherited) is ignored ! — ./Config/xcconfigs/iOSSingleViewApp-Debug.xcconfig FRAMEWORK_SEARCH_PATHS = $(inherited) $ (PROJECT_DIR)/Carthage/Build/iOS — ./Pods/Target Support Files/Pods-iOSSingleViewApp/ Pods-iOSSingleViewApp.debug.xcconfig FRAMEWORK_SEARCH_PATHS = $(inherited) "$ {PODS_ROOT}/TwitterCore/iOS" "${PODS_ROOT}/ TwitterKit/iOS" © Toshihiro Suzuki 2017 13

Slide 14

Slide 14 text

On CI.. e.g. fastlane's increment_version_number depends on agvtool © Toshihiro Suzuki 2017 14

Slide 15

Slide 15 text

Migration failed! — Unwanted FRAMEWORK_SEACH_PATHS diff ! — Failed to increment version using agvtool © Toshihiro Suzuki 2017 15

Slide 16

Slide 16 text

How $(inherited) works? — Inherites from parent LEVEL's value in Build Settings — Does NOT work for #include © Toshihiro Suzuki 2017 16

Slide 17

Slide 17 text

App's FRAMEWORK_SEACH_PATHS overwri!en CocoaPods's © Toshihiro Suzuki 2017 17

Slide 18

Slide 18 text

Fix ✅ Set FRAMEWORK_SEACH_PATHS in rootObject's xcconfig © Toshihiro Suzuki 2017 18

Slide 19

Slide 19 text

Why agvtool failed to update version? — Answer: agvtool is not clever enough — It does NOT search for INFOPLIST_FILE value in xcconfig. © Toshihiro Suzuki 2017 19

Slide 20

Slide 20 text

Workaround #1 Restore INFOPLIST_FILE in Xcode's buildSettings section © Toshihiro Suzuki 2017 20

Slide 21

Slide 21 text

Workaround #2 Use /usr/libexec/PlistBuddy instead of agvtool e.g. APP_VERSION=$(git describe --tags --abbrev=0) BUILD_VERSION=$BITRISE_BUILD_NUMBER /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${APP_VERSION}" AbemaTV/Info.plist /usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${BUILD_VERSION}" AbemaTV/Info.plist © Toshihiro Suzuki 2017 21

Slide 22

Slide 22 text

Summary © Toshihiro Suzuki 2017 22

Slide 23

Slide 23 text

$(inherited) — works btw LEVELs but not for #include INFOPLIST_FILE — agvtool compatibility © Toshihiro Suzuki 2017 23

Slide 24

Slide 24 text

xcconfig-extractor Options: --no-trim-duplicates [default: false] --no-edit-pbxproj [default: false] --include-existing [default: true] --no-set-configurations [default: false] © Toshihiro Suzuki 2017 24

Slide 25

Slide 25 text

End © Toshihiro Suzuki 2017 25

Slide 26

Slide 26 text

Toshihiro Suzuki Feel free to reach out! Twitter: @toshi0383 GitHub: @toshi0383 Qiita: @toshi0383 Email: [email protected] © Toshihiro Suzuki 2017 26