15

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?

Community
  • 1
  • 1
Flagbug
  • 2,093
  • 3
  • 24
  • 47
  • 1
    Yes, it would be nice if Xamarin provided hooks into the build process. That way we could customize the commands without requiring UI support. – Kiliman Aug 27 '15 at 14:19

4 Answers4

2

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.

J-Boss
  • 927
  • 4
  • 14
  • I'm pretty sure the Xamarin Linker will only strip out Bytecode and not Resource files :( – Flagbug Sep 05 '15 at 10:39
  • 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.:) – J-Boss Sep 05 '15 at 11:17
1

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>
Sunseeker
  • 1,503
  • 9
  • 21
  • Sorry for the late reply, but the linker or the mandroid configuration doesn't seem to make any difference – Flagbug Sep 04 '15 at 20:16
0

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.

Flagbug
  • 2,093
  • 3
  • 24
  • 47
0

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
Dennis Vash
  • 50,196
  • 9
  • 100
  • 118