如何用Xamarin.Android删除最终APK文件中未使用的语言?[英] How do I remove unused languages from the final APK file with Xamarin.Android?

本文是小编为大家收集整理的关于如何用Xamarin.Android删除最终APK文件中未使用的语言?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我已经添加了一些android支持库到我的项目,现在我基本上面临着同样的问题,如下所述的问题: Android Studio从支持库导出到APK

因为我不能使用XAMARIN使用GRAMELE设置,因此我无法使用StackOverflow答案中描述的解决方案.

有没有人有一个想法,如何只能在我的最终APK文件中保持特定的本地化?

推荐答案

所以我终于以sane方式设法这样做了

  1. 下载Apktool从 https://ibotpeaches.github.io/apktool/
  2. 用Xamarin创建你的最终的.apk并用apktool d MyApp.apk
  3. 反编译它
  4. 进入MyApp目录,该目录已创建并查找res目录
  5. 删除所有values目录,这些目录以您不需要的语言标识符结束,例如,如果您的应用只支持德语语言,请删除values-fr,values-es等...,但不是. not 删除非语言目录,例如,values-v11!
  6. 用apktool b MyApp
  7. 重新编译您的应用程序
  8. 重新编译的应用程序包现在处于MyApp/dist/MyApp.apk中.拍摄此文件并使用signtool签名,然后zipualign签名.
  9. 将APK上传到Google Play

我确定这个过程可以自动化,我会尽快更新此答案,因为我有一个脚本.

其他推荐答案

通常,在Xamarin中,Androidmanifest处理库的特殊说明,用于库android.app.useslibraryAttribute(String Name ,Bool 所需)设置特定夹杂物并且排除将在生成的manifest.xml中.

据我所知,只有三种方法来设置链接排除,@Sunseeker提到了第一个和第二种,但是Xamarin文档和DEV笔记强烈建议不要使用上面所示和一般倡导者使用以下倡导者:

sdkonly(默认)

上面还提到的第二个是针对特定的排除,它也建议不要使用它,除非您确定特定包在层次结构中进一步提出的扩展类未被扩展的类别被称为"在幕后".

最后在第三种方法中是将LinkMode设置为无,而使用AndroidManifest接口规定特定链接.

一些效率的其他方法是:

  1. 将AndroiduseSharedRuntime属性设置为True,至少在调试时减少包大小.

  2. 将aotassemblies属性设置为true,当您具有稳定的构建以将所包含的库预编译.

  3. 将EmbedassembliesIntoapk设置为false,除非它是发布构建.

这就是随着迄今为止的建立知识与Xamarin一起进行,希望它有所帮助.

其他推荐答案

无法真正检查它,但是你有看看AndroidLinkSkip和AndroidLinkMode(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?

推荐答案

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.

其他推荐答案

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.

其他推荐答案

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>