Xamarin Android Bindings - android

I'm trying to create bindings for the android sdk provided here https://www.nmi.com/sdks-and-apis#CDNA. The binding project builds, and I can add it into my xamarin android project but as soon as I include it I get the following error/s.
error: package com.creditcall.chipdnamobile does not exist
com.creditcall.chipdnamobile.IApplicationSelectionListener ChipDnaSample.Android
C:\Users\mikee\Documents\GitHub\ChipDna\ChipDnaSample\ChipDnaSample.Android\obj\Debug\90\android\src\mono\com\creditcall\chipdnamobile\IApplicationSelectionListenerImplementor.java 8
error: package com.creditcall.chipdnamobile does not exist private
native void n_onAvailablePinPads
(com.creditcall.chipdnamobile.Parameters
p0); ChipDnaSample.Android C:\Users\mikee\Documents\GitHub\ChipDna\ChipDnaSample\ChipDnaSample.Android\obj\Debug\90\android\src\mono\com\creditcall\chipdnamobile\IAvailablePinPadsListenerImplementor.java 33
There are 64 errors of the same nature just referencing different classes. I've put all the code on GitHub here
If I go into Obj/Release/generated/src I can find IApplicationSelectionListener so it is created some binding but it doesn't actually work. Could someone point me in the right direction about what I need to do to correct errors such as these?
Thanks

You have to change the build type of the jars. The java compile can't find it, because it's not present at compile time.
Change
InputJar to EmbeddedInputJar for ChipDnaMobile.jar
ReferenceJar to EmbeddedReferenceJar for CardEaseXMLClient.jar
For more info see: https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-a-jar
The important sentences:
Typically, you use the EmbeddedJar build action so that the .JAR is automatically packaged into the bindings library. This is the simplest option – Java bytecode in the .JAR is converted into Dex bytecode and is embedded (along with the Managed Callable Wrappers) into your APK. If you want to keep the .JAR separate from the bindings library, you can use the InputJar option; however, you must ensure that the .JAR file is available on the device that runs your app.

Related

Xamarin java binding ignores support jar

I need to use http://viewpagerindicator.com/ to add static tabs below the actionbar on a Xamarin.Android project.
I downloaded the project and migrated it from maven to gradle to build it into an AAR file suitable for Xamarin consumption. I created a java binding project, added the AAR file as a LibraryProjectZip and added the v13 support jar as a ReferenceJar but it seems it is being lost somewhere in the way as evidenced by these xbuild logs:
BINDINGSGENERATOR: warning BG8C00: For type Com.Viewpagerindicator.IPageIndicator, base interface android.support.v4.view.ViewPager.OnPageChangeListener does not exist.
BINDINGSGENERATOR: warning BG8800: Unknown parameter type android.support.v4.view.ViewPager.OnPageChangeListener in method SetOnPageChangeListener in managed type Com.Viewpagerindicator.IPageIndicator
BINDINGSGENERATOR: warning BG8800: Unknown parameter type android.support.v4.view.ViewPager in method SetViewPager in managed type Com.Viewpagerindicator.IPageIndicator
The warnings chain continues for a long time, ending the process with a severely limited port
as the missing types make the methods depending on them to vanish away.
If i remove the support jar, the build fails because of missing classes from a utility named jar2xml, leading me to believe it is only used for part of the compilation/mapping process.
The support jar was taken from an unmodified android sdk at extras/android/support/v13/android-support-v13.jar.
Any help is most welcome.
There is a workaround to make these things work.
In my example, I had 2 reference jars (android-support-v4.jar and google-play-services.jar).
So if you just add these 2 jars with Build Action = ReferenceJar, you will see same errors as you posted.
BINDINGSGENERATOR: warning BG8800: Unknown parameter type com.google.android.gms.maps.model.Marker in managed type Com.Google.Maps.Android.MarkerManager.
Though the Marker and MarkerManager classes are defined in the jars, they're not getting resolved correctly on the C# side. To fix that you need to do is to just add already compiled C# bindings for these jars as references.
In my case I used Xamarin.GooglePlayServices package which had a dependency Xamarin.Android.Support.v4 (exactly as my jars).
In your case, you just need to add Xamarin.Android.Support.v4 package to your binding project.
In the end you will have something like this in your project structure:
Hope that helps!

Using cwac-camera via JARs

I'm using the commonsguy cwac-camera library, as per the demo-layout example, documented in "Working directlly with cameraview".
All is fine referencing camera/ and camera-v9/ as Android library projects in source form (I need Android 2.3 compatibility, that's what camera-v9 is for).
When I switch to using the library via JARs:
- cwac-camera-v9-0.6.8.jar only includes CameraFragment and BuildConfig classes, so I need also cwac-camera-0.6.8.jar with the other classes.
- including both JARs causes the following self-explaining error when running the project (not at compile time) Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/commonsware/cwac/camera/BuildConfig;
I could just use the source as library project, or use Gradle, but I want to know if this is a bug to open an issue on Github, or if I'm doing something wrong.
To replicate the error, just clone the demo-layout example add both .jar files to libs folder, and run the project.
No, this appears to be my fault. They must have changed something in the Gradle build process that I am using to create the JARs. I will try to fix this tomorrow. In the meantime, you could go into the cwac-camera-v9 JAR and try removing the classes in com.commonsware.cwac.camera, leaving only those classes incom.commonsware.cwac.camera.acl.
My apologies for this, and thanks for pointing it out!

Cyanogenmod android.jar file

I'm attempting to write an application which uses a few classes and constants that were added to cyanogenmod and do not exist within the standard andriod api.
My question is, using the android SDK, eclipse and ADT, is it possible to get and build against a cyanogenmod version of the andriod.jar file?
In case anyone else ends up in this situation.
Since the andriod.jar file which is used during compilation is basically a set of stubs, I created a separate jar file of my own, with stubbed out versions of the necessary classes & constants, and included that class at compile time for my app (using maven scopes in my case).

Import Android APK archive?

Can an Android APK archive be imported into another Android project and accessed the same way as a JAR archive can?
No not in the way you would use a jar. If you have a java library that you want to import into your project you can simply add it as in any other java project.
If you have the project files of an app that you want to integrate in you application you can create an android library project out of this app. This enables you to build a R file for the layout objects and drawables etc. of the library that is also consistent in the project that includes this library project.
I think that you actually can at runtime (assuming read permissions) but you cannot resolve imports at the java compilation stage since you don't have any java class files, only dex class files that were made from them. So you'd need java stubs or "headers" to stand in for those functions during the java stage of compilation - or possibly try to "link" to them manually at runtime using reflection.

Android adding external libraries to project

I have a project that I would like to add external libraries to (and have them packaged with the application) but I am not sure it is happening. I read on this link:
https://developer.android.com/guide/appendix/faq/commontasks.html
how to, but they do not show up in any of the /data/data/project directories. Does anyone know how I can confirm that the libraries were in fact added to the project for use at runtime? Thanks.
If you include jars as External Jars under your project's Java Build Path, then the classes will be converted to Dalvik format and be made available in your project's classes.dex file, packaged into the .apk.
To confirm they are available, attempt to use something from the jar (Eclipse should suggest the relevant import when you first supply a class name) build and run the app and see if it works? If it works in development (e.g. from 'run' in Eclipse) then it will also work when the app is built in release and distributed as an APK.
You can also place jar under one of your source folders (perhaps creating special "libs" one) and adding it to build path.
Be warned - external libraries (which are compiled against some version or other of the libraries in a Java JDK) may sometimes have problems when running under android. This is because the Dalvik runtime has its own Java framework libraries, which provide most (but not all) of the Java APIs in the standard JDK Java framework libraries.
You should really recompile any external library against the android libraries so that you can see any missing APIs at compile time - and fix the issues there and then. Otherwise you run the risk of runtime errors under Dalvik when you call the external library from your Android app. See http://geekswithblogs.net/cyberycon/archive/2011/05/17/using-external-libraries-with-android.aspx
for more details.

Categories

Resources