Forum Xamarin Xamarin.Android

Shared Resource with Java Bindings Library

MatthiasMatthias DEMember ✭✭
edited October 2012 in Xamarin.Android


i try to abuse the Java Bindings Library together with an Android library project as container for shared resources (layouts, drawables, strings and so on).

In general it's working but some pieces not working very well.

Atsushi Eno mentioned on the mailinglist:

In short, library project resources are supported when you zip relevant
library project build results (in "bin" directory in the Java project)
and embed it as "LibraryProjectZip" in a Java binding library project.

What are the relevant pieces? The bin folder contains nothing except drawables (no layouts, strings ...). As workaround i just zipped the regular res folder and added it as LibraryProjectZip. That works but this also means you don't even need a Android Library.

  1. The zip (with the resources in it) is embedded into the binding library dll and the whole dll is part of the apk file. So the resources are embedded twice, once in the dll and once as regular resources. Is there any way to exclude the dll from the apk creation process? There is no code in it so it's total useless and I only need it a resources provider.

The above wouldn't be necessary if regular M4A libs would support resources as well. So is there any update on the due date for that feature?

Thx for time


  • The above wouldn't be necessary if regular M4A libs would support resources as well

    I heard through the grapevine that this is slated for next MfA release. It is a key feature for building more reusable MfA code, and I am looking forward to it :-).

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    The Android Library project is different from a regular JAR or Android
    project - for example it can't be compiled into an APK and deployed to
    a device or exported to a JAR. Because of this, setting up the Mono
    for Android Java Binding is slightly different.

    First you build the Android Library in Eclipse or with Ant (don't use
    IntelliJ). Then zip the bin & res folders from the Eclipse project.
    Copy that zip to the Mono for Android Java Binding project, and make
    sure it's Build Action is set to ProjectLibraryZip. If the library
    project needs any reference JAR's, add those to the Mono for Android
    Java Binding project as well. Adjust the metadata mappings as
    appropriate. Done.

    This is being added to the Java Binding walkthrough, which should be up pretty soon.

  • MatthiasMatthias DEMember ✭✭

    I'm totally aware of how I have to do it because as I said it's working. The problem is that all resources are embedded twice and that's for sure not wanted!

    Just a short guide how I did it:

    1. Zip the whole res folder from Eclipse. Casing is important for some parts and the folder is called different in VS so I stick to Eclipse. Content looks like this (regular folder structure)

      |- drawable
      |- layout
      |- values
    2. Create a dummy empty jar file. It's necessary for the Jave Binding Library to compile.

    3. Create a Java Binding Library Project in VS. Add the Dummy.jar from (2) as InputJar and the zip from (1) as LibraryProjectZip.

    4. Create an Android Application Project with your shared Activities and so on. Add the project from (3) as reference. It should generate all the necessary R stuff now.

    5. The project from (3) and (4) together are your shared library and must be referenced in your real final Android Application Project. If you compile it should generate the Resoures.Designer.cs with your local project resources and the whole stuff from (3). You should have at least one resource file in your parent project else it fails (dunno why). If you have resources with same name parent wins.

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    The problem is that all resources are embedded twice and that's for sure not wanted!

    It is and it isn't. :-)

    Removal of particular embedded resources is done as a linker step, which will only be performed with Release builds. Consequently, I would expect you to see such duplication of resources in Debug builds, but you should not see it in Release builds (as the "duplicate" EmbeddedResource resources should be removed).

    If you do not see duplicates removed in Release builds, please file a bug.

Sign In or Register to comment.