mac-cain13 / R.swift

Strong typed, autocompleted resources like images, fonts and segues in Swift projects
MIT License
9.49k stars 763 forks source link

R.swift usage causes build error when running `xcodebuild -exportLocalizations` #889

Open finebel opened 6 months ago

finebel commented 6 months ago

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.

Screenshot 2024-03-22 at 14 50 14

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!

finebel commented 6 months ago

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