R.swift
R.swift copied to clipboard
R.swift usage causes build error when running `xcodebuild -exportLocalizations`
Hey folks,
we are using R.swift in our codebase to access all localized strings. Now we are trying to export our localizations via the xcodebuild -exportLocalizations
command.
Unfortunately it cannot build the project, since it always fails with a cannot find 'R' in scope
error for each usage of R.string.<...>
. However, the error only occurs if we are using the xcodebuild -exportLocalizations
command directly. If we use the UI option via Product -> Export Localizations, the export works just fine.
I have created a demo project replicating the issue: https://github.com/finebel/LanguageSample
It seems like the RswiftGenerateInternalResources
build tool plugin isn't executed if I use xcodebuild -exportLocalizations
and the previously (during a normal build) generated R.generated.swift
file is not used.
xcodebuild -exportLocalizations \
-project LanguageSample.xcodeproj \
-localizationPath "<export path>" \
-exportLanguage en
Has anyone experienced something similar or has an idea what the problem might be? Any help is appreciated!
After I have revisited the build logs of an export through the UI option, I found an easy workaround:
Just disable automatic string extraction by setting SWIFT_EMIT_LOC_STRINGS=NO
in the build settings (or pass it directly when invoking xocdebuild -exportLocalizations ...
).
This way there is no build required.
Documentation: https://developer.apple.com/documentation/xcode/build-settings-reference#Use-Compiler-to-Extract-Swift-Strings