Bug 56157 - BindProcessToNetwork doesn't work on android 5
Summary: BindProcessToNetwork doesn't work on android 5
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: Android+BCL Integration ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2017-05-10 02:20 UTC by Daniel Hughes
Modified: 2017-06-28 17:41 UTC (History)
2 users (show)

Tags: bb
Is this bug a regression?: ---
Last known good build:


Attachments
Bug56157.zip (28.99 KB, application/zip)
2017-06-28 17:40 UTC, Marek Habersack
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Daniel Hughes 2017-05-10 02:20:26 UTC
Calling ConnectivityManager.BindProcessToNetwork on an android 5 device results in the following exception:

{Java.Lang.NoSuchMethodError: no non-static method "Landroid/net/ConnectivityManager;.bindProcessToNetwork(Landroid/net/Network;)Z"
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
  at Java.Interop.JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x00068] in /Users/builder/data/lanes/3511/ce955cc0/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11240 
  at Java.Interop.JniType.GetInstanceMethod (System.String name, System.String signature) [0x0000f] in /Users/builder/data/lanes/3511/ce955cc0/source/Java.Interop/src/Java.Interop/Java.Interop/JniType.cs:228 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.GetMethodInfo (System.String encodedMember) [0x0003a] in /Users/builder/data/lanes/3511/ce955cc0/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:94 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00023] in /Users/builder/data/lanes/3511/ce955cc0/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:61 
  at Android.Net.ConnectivityManager.BindProcessToNetwork (Android.Net.Network network) [0x0002c] in /Users/builder/data/lanes/3511/ce955cc0/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Net.ConnectivityManager.cs:743 
  at HeadExtension.Droid.Services.NoWifiDirectService..ctor (Android.Content.Context context) [0x00053] in C:\Work\HeadExtension\src\HeadExtension.Droid\Services\NoWifiDirectService.cs:24 
  --- End of managed Java.Lang.NoSuchMethodError stack trace ---
java.lang.NoSuchMethodError: no non-static method "Landroid/net/ConnectivityManager;.bindProcessToNetwork(Landroid/net/Network;)Z"
	at mvvmcross.droid.views.MvxSplashScreenActivity.n_onResume(Native Method)
	at mvvmcross.droid.views.MvxSplashScreenActivity.onResume(MvxSplashScreenActivity.java:39)
	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1257)
	at android.app.Activity.performResume(Activity.java:6104)
	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2975)
	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3017)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:135)
	at android.app.ActivityThread.main(ActivityThread.java:5254)
	at java.lang.reflect.Method.invoke(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:372)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
}
    base: {Java.Lang.IncompatibleClassChangeError}
    JniPeerMembers: {Android.Runtime.XAPeerMembers}

Interestingly the API was introduced in API23 and (android 6) and android 5 required has a different call setProcessDefaultNetwork which is obsolete in API23 and is not wrapped at all in Xamarin. At least not when targeting API23
Comment 1 Daniel Hughes 2017-05-10 03:10:02 UTC
I've discovered that setProcessDefaultNetwork is static and using it does work on android 5 however you get a horrible warning about it being obsolete. Seems that the new API should work on android 5 but doesn't
Comment 2 Mark McLemore 2017-06-28 00:08:41 UTC
Thank you for taking the time to submit the bug. We are unable to reproduce this issue from the description. Please attach a reproduction to the bug by starting with a clean Xamarin.Android project and adding just the code necessary to demonstrate the issue.
Comment 3 Marek Habersack 2017-06-28 17:40:33 UTC
Created attachment 23179 [details]
Bug56157.zip

I tried to reproduce the issue with the attached app and the application works fine with the current xamarin-android/master. 

@Daniel, the setProcessDefaultNetwork API is bound by Xamarin.Android (as ConnectivityManager.SetProcessDefaultNetwork) but is marked obsolete, just like upstream.

I'm going to close the bug but please feel free to reopen it if you are able to reproduce the issue with the attached application (either as attached or after modifying it. In the latter case please attach the modified sample in its entirety) and please make sure to state versions of Xamarin.Android and the IDE you're using, thanks!
Comment 4 Marek Habersack 2017-06-28 17:41:16 UTC
Unable to reproduce with xamarin-android/master