Forum Xamarin.Android

Binding to java jcifs library

I am evaluating Xamarin (v4.8) and for my Android application I would like to read files from Windows shared folders.

In Java application I was able to do this with using jcifs library. When I tried to add java binding to Xamarin project, I was not able to do this.

First I got error:
'Name': member names cannot be the same as their enclosing type D:\Android\Xamarin\XamarinTest1\JCIFS\obj\Debug\generated\src\Jcifs.Netbios.Name.cs

I have added the following:

This helped for the previous error, but produces 5 new errors about wrong access modifies - for example:
'Jcifs.Util.MD4.EngineDigest()': cannot change access modifiers when overriding 'protected' inherited member 'Java.Security.MessageDigestSpi.EngineDigest()' D:\Android\Xamarin\XamarinTest1\JCIFS\obj\Debug\generated\src\Jcifs.Util.MD4.cs

I have fixed that with:

After that all hell break loose - I got 289 (!!!) errors. At that point I gave up.

I have also seen that in the release notes for v4.8 the following bug is marked as fixed:
11783: jcifs: binding generator tools miss some methods that involves derivation in different jars

I would suspect that fixing that bug would mean that jcifs can now be bound without any problems.

Therefore I am asking if it is possible to use jcifs in Xamarin?

I think that accessing windows shares could be quite important for .net developers for Android in iOS.

Therefore I have two recommendations:
1) jcifs is just one of the commonly used java library - it would be great if you at Xamarin would prepare open source Java Binding libraries for the most common use cases - with already defined Metadata.xml and other adjustments to build the projects. This would be much easier done by you because you have much more experience than we have (and it could be also used to improve the binding mechanism). You should also list the java libraries that cannot be binded - so we (other developers) will not lose time with trying to find the magic formula.

2) It would be great if you at Xamarin would invest some time to convert the jcifs library into .net library (this would make it useful for iOS also). I am sure that this could be very useful for many Xamarin users - especially for business applications that are used internally in the companies (and need access to internal company storage). You could also sell it in your components store. Maybe even Microsoft could be interesting in helping you with that - if they can provide you the native c++ code to connect to shared folders and you could add cifs support natively this would be amazing (using jcifs from java is already quite slow).


  • After quiet a lot of struggle I have found a way to create working jcifs library binding in Xamarin.

    The trick was to first copy the generated binding files from obj\Debug\generated\src to some other folder (just to create a copy of the cs files). Than I have changed the Metadata.xml file to prevent generating any binding files:

    Than I have manually added some of the cs files (only those that I needed) of the jcifs library to the project. This was done by copying the files from previously copied folder (generated cs files) to the project's Additions folder.

    Luckily the files that I needed (smb support) were all correctly created by previous code generation so the project build without errors (it looks like all the 289 errors - mentioned in the previous post - were all in the files that were not needed for me - for example I do not need to access the NetBios interface from c# code).

    This approach is quite different from the "official" Xamarin approach - there xamarin tries to import all the classes and properties except the ones that are excluded with "remove-node" element. In my approach I "imported" only the classes that are needed (from many classes defined in jcifs I really need only SmbFile, NtlmPasswordAuthentication and SmbFileInputStream).

    I tried to use this approach with changing Metadata.xml (and without copying cs files to Additions) but did not find a way to do it - start with empty list of classes to bind and than adding the ones that I need. If this is not yet possible, than you at Xamarin should think about adding support - it can prevent binding problems and also create much smaller binding assembly.

    For those who would also like to use jcifs in Xamarin project, I am attaching the source code for the jcifs binding project.

  • BilliBonceBilliBonce USMember
    edited April 2014

    I try to get files from a shared folder protected username and password.
    Using jcifs works perfectly. On API Level 2.2
    If application properties changed to:
    Compile using android version: API Level 4.2
    Minimum Android to target: API Level 4.2
    Target Android version: API Level 4.2
    I have error:

Sign In or Register to comment.