Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
finebel opened this issue Mar 22, 2024 · 1 comment

Comments

@finebel
Copy link

finebel commented Mar 22, 2024

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 finebel changed the title R.string usage causes build error when running xcodebuild -exportLocalizations R.swift usage causes build error when running xcodebuild -exportLocalizations Mar 22, 2024
@finebel
Copy link
Author

finebel commented Mar 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant