Question

I'm having trouble trying to port Card.IO to Xamarin Android. Since I am using C# instead of Java, I don't know what to do with the .so files and the .jar files.

I tried to follow some of the steps posted here : card.io Mono for Android (Xamarin Studio) but I am getting the following two build errors that I don't know how to solve.

Here's What I've done so far

  1. Create a new Android Java Bindings Library Project

  2. Add the .jar and .so files from Card.IO project, with the existing folder structure. So there is four subfolders under the /libs folder, and then a single jar under /libs.

  3. Add the following to Transforms/EnumMethods.xml to resolve a compiler error:

    <mapping jni-class="io/card/payment/CardIOActivity">
        <method jni-name="onActivityResult" parameter="p1" clr-enum-type="Android.App.Result" />
    </mapping>
    
  4. Add a reference to the above Library in my main application.

And then I am faced with these build errors :

The type or namespace name 'IN' does not exist in the namespace 'IO.Card.Payment' (are you missing an assembly reference?)

'A': member names cannot be the same as their enclosing type

Update

The first error is on this line :

public sealed partial class CardIOActivity : global::Android.App.Activity, global::IO.Card.Payment.IN {

The second error seems to be on this line :

public static global::System.Collections.IList A {

Any help is useful, thanks!

Was it helpful?

Solution

i've spent like 10 hours yday to get card io working with my xamarin application... after long long battles i managed to see what i wanted... i did not see the above error about 2 interfaces, i've had an issue with 'a' field in 'A' class and there as an error telling that "IN" interface does not exist (this is an interface, so no problem with double base class should be shown there, that's odd).

not sure if all my steps are necessary to make it working but (surprise, surprise) i was to tired to clean that up and check which chagnes were really essencial. lots of problems are cause by the code obfuscation of the card io jar. nevermind, back to the topic:

  1. create new binding project, add the jar as embeded jar, add the .so files as embided native libraries (use the existing structure)
  2. open EnumMethods.xml and add there a mapping:

<mapping jni-class="io/card/payment/CardIOActivity">

<method jni-name="onActivityResult" parameter="p1" clr-enum-type="Android.App.Result" />

</mapping>

(this changes int to enum type used by .net xamarin in the onActivityResult method (which is overloaded by one of the classes in card.io.jar) 3. open Metadata.xml and add below nodes (some might be unnecessary):

<attr path="/api/package[@name='io.card.payment']/class[@name='A']/field[@name='a']" name="managedName">AProp</attr>

  <attr path="/api/package[@name='io.card.payment']/class[@name='M']" name="visibility">public</attr>
  <attr path="/api/package[@name='io.card.payment']/class[@name='M']" name="name">Mcl</attr>

  <attr path="/api/package[@name='io.card.payment']/interface[@name='N']" name="visibility">public</attr>
  <attr path="/api/package[@name='io.card.payment']/interface[@name='N']" name="name">Nifc</attr>

  <attr path="/api/package[@name='io.card.payment']/class[@name='L']" name="visibility">public</attr>
  <attr path="/api/package[@name='io.card.payment']/class[@name='L']/field[@name='a']" name="managedName">aProp</attr>
  <attr path="/api/package[@name='io.card.payment']/class[@name='L']/method[@name='a']" name="managedName">aMethod</attr>
  <attr path="/api/package[@name='io.card.payment']/class[@name='L']" name="name">Lcl</attr>

above nodes change some visibilities to public (most needed) and change some names of classes or iterfaces (not sure if needed, but it was useful to me at some point)

  1. add reference to the binding project in the main one.

  2. open AndroidManifest.xml in the main project and add there:

<activity android:name="io.card.payment.CardIOActivity" android:configChanges="keyboardHidden|orientation" />

<activity android:name="io.card.payment.DataEntryActivity" android:screenOrientation="portrait"/>

nodes should be added under application node (which is a child of main node - manifest)

  1. now you should be able to invoke the CardIOActivity and use what you want (invoking and using is available and seems to be described well in the examples provided by the creators)

  2. one more hint, nothing big, but when i finally succeeded in getting the library working i missed it... to get result as CreditResult object in OnActivityResult method use java cast: var scanResult = data.GetParcelableExtra(CardIOActivity.ExtraScanResult).JavaCast(); ordinary c# cast won't work.

if you have any problems let me know, perhaps i missed something (especially that i'm not yet xamarin expert).

good luck!

ps: answer placed @xamarin forum too

EDIT: Completet solution with binding, checked and working uploded to github: https://github.com/wiadran/card.io.xamarin.binding.git

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top