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?

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.

How do I remove unused languages from the final APK file , I've added some of the Android support libraries to my project and Since I can't use Gradle settings with Xamarin, I can't use the Does anyone have an idea, how I can keep only specific localization in my final APK file? Android manifest file merge rules in Xamarin.Android. No APK files in Xamarin.Android. Answered. How do I remove unused languages from the final APK file? in

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>

How do I remove unused languages in released or signed APK file , How do I remove unused languages from the final APK file with Xamarin.Android ? - android. First, in Visual Studio, right-click your Xamarin.Android project in the Solution Explorer and select Properties. Then, go to the Android Manifest tab, to see this screen: Unlike in Android Studio or Eclipse, you don't need the set the AndroidManifest.xml file by writing; Xamarin and Visual Studio do that for you.

So I've finally managed to do this in a sane way

  1. Download Apktool from https://ibotpeaches.github.io/Apktool/
  2. Create your final .apk with Xamarin and decompile it with apktool d MyApp.apk
  3. Go into the MyApp directory that Apktool has created and look for the res directory
  4. Remove all values directories that end with a language identifier that you don't need, e.g if your app only supports the German language, remove values-fr, values-es, etc..., but not values-de. Don't remove non-language directories, e.g values-v11!
  5. Recompile your app with apktool b MyApp
  6. The recompiled app package is now in MyApp/dist/MyApp.apk. Take this file and sign it with the signtool, then zipalign it.
  7. Upload the apk to Google Play

I'm sure this process can be automated, I'll update this answer as soon as I have a script for that.

Removing unused language resources from an Android APK when , I remove unused languages from the final APK file with Xamarin.Android? which is not working. How can i keep only specific localization in my release APK ? This content includes language strings and styles, as well as paths to content that is not included directly in the resources.arsc file, such as layout files and images. Note: Do not compress this file in your APK. classes.dex: Contains the classes compiled in the DEX file format understood by the Dalvik/ART virtual machine.

Have you tried solution from Borris Spinner:

You can provide AndroidResgenExtraArgs in your project file and add -c en,de etc.

See aapt documentation:

-c  specify which configurations to include.  The default is all
       configurations.  The value of the parameter should be a comma
       separated list of configuration values.  Locales should be specified
       as either a language or language-region pair.  Some examples:
            en
            port,en
            port,land,en_US

Xamarin.Android, Removing unused language resources from an Android APK when developing with Xamarin. Create your final .apk with Xamarin and decompile it with apktool d MyApp.apk. Go into the MyApp directory that Apktool has created and look for the res directory. The final APK delivered to the user’s device would contain the minimal APK required for the application to run on device. Inspecting the DEX file. Other than being 2.0MB towards our APK size, the classes.dex file does not have much insight other than seeing a distribution of where methods are defined inside your application and third-party

40303 – no way to define, override or configure "resConfigs", xamarin.android documentation: Preparing your APK in the Visual Studio. the set the AndroidManifest.xml file by writing; Xamarin and Visual Studio do that for you. This will make the Xamarin Linker to remove all unused classes from SDK and your NET � C# Language � F# � firebase � iOS � Java Language � Xamarin. 2nd question in my app, the user is able to change the language. Should I only set .NET culture or both the .NET culture and Android Locale.Default? What's the relationship between the .NET and Locale.Default? java.util.Locale defines the culture information in the following format: <language code>[_<country code>[_<variant code>]]

Xamarin.Android, If you're developing with Xamarin for Android, you're out of luck, there -do-i- remove-unused-languages-from-the-final-apk-file-with-xamarin-� By default the Linker in Android release mode is set to Link SDK Only.You can strip more unused IL code from the assemblies by setting it to Link All Assemblies, but beware, the linker works on static code references, so any code usage ref'd by reflection would not be seen and removed.

Xamarin.Android 10.1, This will make the Xamarin Linker to remove all unused classes from SDK and your Android apps, and also will reduce the APK file size and obfuscate the Java code. in D:\repos\octokit.net\Octokit\Http\Connection.cs:574 --- End of stack trace from NET � C# Language � F# � firebase � iOS � Java Language � Xamarin. The Xamarin.Android app determines the path to the file that will be manipulated, then uses standard .NET idioms for file access. Because the actual paths to internal and external storage may vary from device to device or from Android version to Android version, it is not recommended to hard code the path to the files.

Comments
  • Yes, it would be nice if Xamarin provided hooks into the build process. That way we could customize the commands without requiring UI support.
  • I'm pretty sure the Xamarin Linker will only strip out Bytecode and not Resource files :(
  • I believe your right about the linker, but with the usesLibraryAttribute w/ the linker should get both, and along with the other reduction it should get you all the way there.:)
  • Sorry for the late reply, but the linker or the mandroid configuration doesn't seem to make any difference