Bug 53250 - Linker is not removing native .so from .dll in .apk
Summary: Linker is not removing native .so from .dll in .apk
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: Linker ()
Version: 7.1 (C9)
Hardware: All All
: --- major
Target Milestone: ---
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2017-03-10 23:38 UTC by Matthew Leibowitz
Modified: 2018-09-14 05:20 UTC (History)
13 users (show)

Tags:
Is this bug a regression?: Yes
Last known good build:


Attachments
Sample Project (56.37 KB, application/zip)
2017-03-10 23:38 UTC, Matthew Leibowitz
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 53250 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Matthew Leibowitz 2017-03-10 23:38:28 UTC
Created attachment 20276 [details]
Sample Project

When building an app that references a .dll with an embedded .so, the linker does not remove the native bits from the managed assembly. It correctly copies the native library into the lib directory in the .apk, but then includes the fat managed .dll instead of stripping the native bits out first.

In the attached project, the SkiaSharp.dll is about 10MB inside the .apk. It should only be a few KB. The native libSkiaSharp.so is in the lib directory correctly.
Comment 1 Matthew Leibowitz 2017-03-10 23:40:38 UTC
The issue is with my machine: https://gist.github.com/mattleibow/339f1955f3545470133b14dccfc58fbe

(And VS on the same versions)
Comment 2 Dmitry 2017-03-21 14:46:57 UTC
https://forums.xamarin.com/discussion/comment/260884#Comment_260884

It's seems, resources are duplicated in apk. Now dll's in apk contains all resources(png, xml), so, e.g. lib's size in apk increased from 300KB to 3.5MB.
Comment 4 Matthew Leibowitz 2017-03-21 16:22:38 UTC
Ok world, I think we managed to find out some areas of where things are going wrong, and are working to fix that ASAP.

As a workaround, there is a simple change to the linker settings. If the "Link all assemblies" option is selected, the files are properly shrunk.

As this may not be possible for some assemblies, especially if there is reflection/deserialization, specific assemblies can be ignored using the "Ignore assemblies" text box.

For example, in this sample if I wish to skip over the "SkiaSharp.Views.Android.dll" assembly, but still link everything else out, I change the linker option to link all, and then enter "SkiaSharp.Views.Android" in the ignore text box. (note: no ".dll" extension)
Comment 5 Dmitry 2017-03-22 07:30:41 UTC
I always use linking sdk and user assemblies. Resources are not shrunk at the latest xamarin version from dll
Comment 6 Radek Doulik 2017-03-29 09:37:43 UTC
To clarify, do you use "Link all assemblies" in the Linker options?
Comment 7 Dmitry 2017-03-29 10:03:45 UTC
Yes. Link all assemblies. Just one note(I forgot to mentioned it), I use Preserve attribute in projects, so custom libraries don't link. But I can't avoid this, because linking cut all default constructors in ViewModels, so Mvvmcross can't create viewmodel
Comment 8 Radek Doulik 2017-03-29 16:08:51 UTC
I have meanwhile worked on the issue in the sample project. I have a fix for cecil waiting for review. https://github.com/jbevain/cecil/pull/368

It should fix the bug.
Comment 9 Andy 2017-04-06 13:32:00 UTC
Is there a fix imminent for this?  It has blown our app from 30MB to 50MB so it is pretty critical
Comment 10 John Graumann 2017-04-19 16:19:22 UTC
We are seeing this issue as well. Our app size has increased by about 10 MB, and the Link all assemblies option is too high risk at this point in our release schedule. Any updates on when a fix will be available?
Comment 11 Ref C 2017-05-02 18:04:56 UTC
Yea, this issue is critical to me. I created a blank app and it was 8 MB. Hopefully this gets addressed soon.