question

RedParrot-2316 avatar image
0 Votes"
RedParrot-2316 asked PaulHam-8830 commented

Resx Localization not working in Android Release

I have an App with a fully working with language localisation using .resx and setting culture info like so

var cultureInfo = new CultureInfo(CurrentLanguage);
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = cultureInfo;
AppResources.Culture = cultureInfo;
MainPage = new NavigationPage(new LoginPage());

But after updating visual studio and Xamarin forms to the latest version, it just stopped working ONLY for Android in Release build. (Works fine in Android debug, iOS debug & release)

In Release, doing AppResources.Culture.DisplayName yields the correct language name but when I access the string with AppResources.Home for example, it gives the default English string. Its like the other languages .resx disappeared or something.

Tried enabling and disabling Multi-Dex, setting Code Shrinker to blank, setting Linker Behaviour to Do Not Link. Cleaned and rebuild after deleting bin and obj files. None worked

Completely stumped on how to proceed. Please advise, thanks.

EDIT: I'm using Xamarin.Forms 5.0.0.2012 and VS for Mac 8.9.1
Last known working is XF 4.8.0.1821 and I can't remember the VS version, but it should be around 2 months ago, so probably 8.7 at least

dotnet-xamarinvs-general
· 9
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What is your VS and Xamarin forms nuget package version? You can also try to install previous VS version by this thread:https://docs.microsoft.com/en-us/visualstudio/releases/2019/history

0 Votes 0 ·

Hi, I can't seem to find installation files for previous versions of VS for Mac. Thanks.

0 Votes 0 ·

I did a clean build in Windows VS 16.8.3 and XF 5.0. and it works.

This seems like a VS Mac update problem. No idea which one or where since I didn't think twice about updating when I got the prompt.

0 Votes 0 ·

Thanks for your sharing, Yes this issue is related to the VS for mac update, here is a similar thread about installing previous version of VS for mac https://forums.xamarin.com/discussion/123413/install-previous-version-of-visual-studio-for-mac the easiest option in general might be to create a support incident to request the version you'd like

0 Votes 0 ·

I also experience this issue. I am using VS for Mac 8.9.2 with Xamarin 5.0.0.2012.
And the workaround here https://github.com/xamarin/xamarin-android/issues/4664 does not work for me.


Therefore I think it is a different problem.

One thing I notice is that if I turn on "enable optimizations" in the Debug Build, the debug build will also have this problem. So I think the "enable optimizations" is doing something under the hood that causes the problem

0 Votes 0 ·

After unchecking the "enable optimizations" for the Release Build and some adjustment, I can deploy the Release Build onto the smartphone and successfully upload to the Google Play Store for closed testing.
And the app displays correct language. So I believe it is the "enable optimizations" feature causing this problem.

0 Votes 0 ·

On VS Mac 8.9.1, can confirm that "Enable Optimizations" causes this problem in debug mode. However, either configuration didn't work in Release mode for me. Maybe its a combination of things?

0 Votes 0 ·

You can try to use Visual Studio 8.10 preview, Others fixed this issue in this preview version :https://developercommunity.visualstudio.com/t/Android-RESX-localization-not-working-in/1318632?space=41&q=Localization&sort=newest

If you do not want to use preview version, here is a workaround: https://github.com/xamarin/xamarin-android/issues/5540#issuecomment-787987044

0 Votes 0 ·

I manage to fix it by disable the "Use fast deployment (debug mode only)" and "Optimize code".

0 Votes 0 ·

0 Answers