Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove unused languages from the final APK file with Xamarin.Android?

I've added some of the Android support libraries to my project and now I'm basically facing the same problem as described in this question: Android Studio exports strings from support library to APK

Since I can't use Gradle settings with Xamarin, I can't use the solution described in the StackOverflow answer.

Does anyone have an idea, how I can keep only specific localization in my final APK file?

like image 520
Flagbug Avatar asked Aug 27 '15 10:08

Flagbug


2 Answers

Generally, in Xamarin, The AndroidManifest handles special instructions for uses of libraries The Android.App.UsesLibraryAttribute(string name, bool required) sets specific inclusions and exclusion that will be in the generated Manifest.XML.

Also as far as I know there are only three ways to set link exclusions, the first and second are mentioned by @sunseeker, however Xamarin documentation and dev notes strongly recommend not using Full as indicated above and in general advocate using the following:

SdkOnly(default)

the second also mentioned above is for specific exclusions, it is also recommended not using this unless you are sure a particular package is not getting called "behind the scenes" by an extended class further up in the hierarchy.

Finally in the third method is to set LinkMode to None, while specific linkings are stipulated using the AndroidManifest interface.

Some other ways to get efficiencies are to:

  1. set AndroidUseSharedRuntime property to true at least while debugging to reduce package size.

  2. set AotAssemblies property to true when you have a stable build to precompile the libraries that are included.

  3. set EmbedAssembliesIntoApk to false unless it is a release build.

That's about as far build knowledge goes with Xamarin, hope it helps.

like image 58
J-Boss Avatar answered Nov 10 '22 03:11

J-Boss


Can't really check it now, but have you had a look at AndroidLinkSkip and AndroidLinkMode (reference) tags in a solution .csproj file?

So, it'd be something like

<AndroidLinkMode>Full</AndroidLinkMode>
<AndroidLinkSkip>Mono.Android.Export;I18N;I18N.West</AndroidLinkSkip>

Also, have a look at MandroidI18n. From the same reference above:

Specifies the internationalization support included with the Application, such as collation and sorting tables. The value is a comma- or semicolon-separated list of one or more of the case-insensitive values

<MandroidExtraArgs>-i18n=west</MandroidExtraArgs> 

or

<MandroidI18n>West</MandroidI18n>
like image 32
Sunseeker Avatar answered Nov 10 '22 04:11

Sunseeker