Why are Class Libraries so big?

Have been trialing Xamarin.Android for the last couple of weeks, testing a few different samples etc and have noticed that the "Android Class Library" dlls are huge compared to just normal "Android Application". What's going on?

For example, I created a really really simple class library with just a few classes and according to code metrics just 12 lines of code. This produces a Release dll of 32.5Kb. If I instead put the exact same files into an application then it comes out to be only 7Kb. It looks to me that it's impossible to use class libraries with the Starter License's 32kb limit.


  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    What else is in your class library project? Any resources (Embedded or Android)? Assets?

    Class libraries can contain EmbeddedResources, Android resources (though it's not necessarily easy), .jar files (via Binding projects), etc., and all of these "resource"-like constructs are embedded into the .dll, allowing you to copy the .dll between directories without necessarily needing to worry about the enclosing project structure.

    These resources do not contribute to the 32KB Starter limit.

    If you build your app with diagnostic MSBuild output, the computed assembly size will be logged. (This may require 4.6.2, but I'm pretty sure it's in 4.6.0.)

  • KuanBartelKuanBartel AUMember

    There is pretty much nothing in the project, no resources just a few classes.

    To make sure, I just made a new library using the default template when selecting "Android Class Library" in Visual Studio. Has a single class in it "Class1" with nothing written in there. There is also the default resources with two strings: "Hello" and "ApplicationName". That's it. Build it.. 33kb.

    Just to test, I removed the resources directory: 31.5Kb. Not much difference and still not usable with starter since the normal app will be minimum 6Kb too giving a total over the 32Kb limit.

  • KuanBartelKuanBartel AUMember

    Ok I think I've worked this out now.

    I tried to use the diagnostic msbuild output but couldn't seem to find anything in the output saying what the computed size was in 4.6.0. Anyway, opening the assembly with dotPeek I identified what was so big. It's from a resource, AndroidLibraryProjects.zip, and specifically the monoandroidsplash.png file within it. I'm assuming that this is only being included since I'm running a trial version. Having no way to tell how big my assembly is calculated to be, using the trial version, makes it very hard to evaluate what level of plan I will require for my software. Hopefully you can push out a stable release soon which will make this clearer to people evaluating the software.

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    couldn't seem to find anything in the output saying what the computed size was in 4.6.0.

    It should be in there:

    Log.LogMessage (MessageImportance.Low, "  code size for {0}: {1}", Path.GetFileName (assemblyFile), currentSize);

    It's not entirely obvious, but there should be a "code size for" message in the diagnostic output.

  • KuanBartelKuanBartel AUMember

    Maybe it's only in there for "Starter" license and not a trial user?
    I searched for "size" and it's not there. You're welcome to look at the output to see if you can find it. Build output attached.

Sign In or Register to comment.