Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OkHttp binding library for Xamarin Android throwing error

I'm attempting to use the OkHttp-Xamarin library in a Xamarin Android application. Whenever I try to create a new OkHttpNetworkHandler I get the exception below.

Line:

var handler = new OkHttpNetworkHandler();

Throws:

[] Missing method Android.Runtime.JNIEnv::AllocObject(Type) in assembly Mono.Android.dll, referenced in assembly /data/data/com.my.app/files/.__override__/OkHttp.dll
[MonoDroid] UNHANDLED EXCEPTION: System.MissingMethodException: Method not found: 'Android.Runtime.JNIEnv.AllocObject'.
[MonoDroid] at ModernHttpClient.OkHttpNetworkHandler..ctor () <IL 0x00001, 0x00057>

I am using prebuilt binaries from ModernHttpClient version 0.9. My minimum Android version is set to 2.3 and target is set to 4.2. I'm using Xamarin Studio 4.0.13 and Mono 3.2.3.

like image 377
jdehlin Avatar asked May 12 '26 08:05

jdehlin


2 Answers

So this looks like the first call to your binding code.

A couple things could be going on here:

  • Make sure you are using EmbeddedJar instead of InputJar as the build action for the jar file. Otherwise, you have to include the jar with your main Android application.
  • Make sure your main application has a reference to the binding DLL, it causes problems if only a dependent project has the reference.

If neither of those fix your issue, let me know, I think there is a working binding Paul Betts has for this library.

like image 160
jonathanpeppers Avatar answered May 13 '26 21:05

jonathanpeppers


Not really an answer to why the Exception is being thrown but at the suggestion of Paul Betts I switched to the Alpha channel and things are working now.

like image 40
jdehlin Avatar answered May 13 '26 22:05

jdehlin