Error calling GoogleCloudMessaging Register

I get an error when calling the Register function for google cloud messaging. I'm using Google Play Services component from the component store. I'm suspicious it's a problem with the Java bindings but not sure, the error doesn't tell me much.

Here's my code:
var gcm = GoogleCloudMessaging.GetInstance(this); var registrationId = gcm.Register("{myAppId}");

And the error:
`An unhandled exception occured.
09-27 11:22:36.609 I/MonoDroid(20947): UNHANDLED EXCEPTION: Java.IO.IOException: Exception of type 'Java.IO.IOException' was thrown.
09-27 11:22:36.609 I/MonoDroid(20947): at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00024] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/b76e8ec4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:145
09-27 11:22:36.609 I/MonoDroid(20947): at Android.Gms.Gcm.GoogleCloudMessaging.Register (string[])
09-27 11:22:36.609 I/MonoDroid(20947): at WIRECOWEBMOB.Droid.Views.ExampleView.OnStart () [0x0000f] in c:_Application\WIRECOWEB.2\src\WIRECOWEBMOB.Droid\Views\ExampleView.cs:22
09-27 11:22:36.609 I/MonoDroid(20947): at Android.App.Activity.n_OnStart (intptr,intptr) [0x00008] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/b76e8ec4/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.App.Activity.cs:2725
09-27 11:22:36.609 I/MonoDroid(20947): at (wrapper dynamic-method) object.cca1eb61-76a3-412e-ae59-60429c7eb0b0 (intptr,intptr)
09-27 11:22:36.609 I/MonoDroid(20947):
09-27 11:22:36.609 I/MonoDroid(20947): --- End of managed exception stack trace ---
09-27 11:22:36.609 I/MonoDroid(20947): java.io.IOException: MAIN_THREAD
09-27 11:22:36.609 I/MonoDroid(20947): at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
09-27 11:22:36.609 I/MonoDroid(20947): at wirecowebmob.droid.views.ExampleView.n_onStart(Native Method)
09-27 11:22:36.609 I/MonoDroid(20947): at wirecowebmob.droid.views.ExampleView.onStart(ExampleView.java:37)
09-27 11:22:36.609 I/MonoDroid(20947): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
09-27 11:22:36.609 I/MonoDroid(20947): at android.app.Activity.performStart(Activity.java:5189)
09-27 11:22:36.609 I/MonoDroid(20947): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2083)
09-27 11:22:36.609 I/MonoDroid(20947): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
09-27 11:22:36.609 I/MonoDroid(20947): at android.app.ActivityThread.access$700(ActivityThread.java:143)
09-27 11:22:36.609 I/MonoDroid(20947): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
09-27 11:22:36.609 I/MonoDroid(20947): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 11:22:36.609 I/MonoDroid(20947): at android.os.Looper.loop(Looper.java:137)
09-27 11:22:36.609 I/MonoDroid(20947): at android.app.ActivityThread.main(ActivityThread.java:4950)
09-27 11:22:36.609 I/MonoDroid(20947): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 11:22:36.609 I/MonoDroid(20947): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 11:22:36.609 I/MonoDroid(20947): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
09-27 11:22:36.609 I/MonoDroid(20947): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
09-27 11:22:36.609 I/MonoDroid(20947): at dalvik.system.NativeStart.main(Native Method)
09-27 11:22:36.730 W/dalvikvm(20947): JNI WARNING: JNI method called with exception pending
09-27 11:22:36.740 W/dalvikvm(20947): in Lwirecowebmob/droid/views/ExampleView;.n_onStart:()V (GetMethodID)
09-27 11:22:36.740 W/dalvikvm(20947): Pending exception is:
09-27 11:22:36.740 I/dalvikvm(20947): "main" prio=5 tid=1 NATIVE
09-27 11:22:36.740 I/dalvikvm(20947): | group="main" sCount=0 dsCount=0 obj=0x418c86a0 self=0x418b1988
09-27 11:22:36.740 I/dalvikvm(20947): | sysTid=20947 nice=0 sched=0/0 cgrp=apps handle=1075411024
09-27 11:22:36.740 I/dalvikvm(20947): | schedstat=( 0 0 0 ) utm=293 stm=22 core=0
09-27 11:22:36.770 I/dalvikvm(20947): #00 pc 00001260 /system/lib/libcorkscrew.so (unwind_backtrace_thread+27)
09-27 11:22:36.770 I/dalvikvm(20947): #01 pc 0005f78c /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+35)
09-27 11:22:36.770 I/dalvikvm(20947): #02 pc 00053f1e /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+289)
09-27 11:22:36.770 I/dalvikvm(20947): #03 pc 00053fae /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25)
09-27 11:22:36.770 I/dalvikvm(20947): #04 pc 0003a23e /system/lib/libdvm.so
09-27 11:22:36.780 I/dalvikvm(20947): #05 pc 000423b2 /system/lib/libdvm.so
09-27 11:22:36.780 I/dalvikvm(20947): at wirecowebmob.droid.views.ExampleView.n_onStart(Native Method)
09-27 11:22:36.780 I/dalvikvm(20947): at wirecowebmob.droid.views.ExampleView.onStart(ExampleView.java:37)
09-27 11:22:36.780 I/dalvikvm(20947): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
09-27 11:22:36.780 I/dalvikvm(20947): at android.app.Activity.performStart(Activity.java:5189)
09-27 11:22:36.780 I/dalvikvm(20947): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2083)
09-27 11:22:36.780 I/dalvikvm(20947): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
09-27 11:22:36.780 I/dalvikvm(20947): at android.app.ActivityThread.access$700(ActivityThread.java:143)
09-27 11:22:36.780 I/dalvikvm(20947): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
09-27 11:22:36.790 I/dalvikvm(20947): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 11:22:36.790 I/dalvikvm(20947): at android.os.Looper.loop(Looper.java:137)
09-27 11:22:36.790 I/dalvikvm(20947): at android.app.ActivityThread.main(ActivityThread.java:4950)
09-27 11:22:36.790 I/dalvikvm(20947): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 11:22:36.790 I/dalvikvm(20947): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 11:22:36.790 I/dalvikvm(20947): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
09-27 11:22:36.790 I/dalvikvm(20947): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
09-27 11:22:36.800 I/dalvikvm(20947): at dalvik.system.NativeStart.main(Native Method)
09-27 11:22:36.800 I/dalvikvm(20947):
09-27 11:22:36.800 E/dalvikvm(20947): VM aborting
09-27 11:22:36.800 E/mono-rt (20947): Stacktrace:
09-27 11:22:36.800 E/mono-rt (20947):
09-27 11:22:36.800 E/mono-rt (20947): at <0xffffffff>
09-27 11:22:36.810 E/mono-rt (20947): at (wrapper managed-to-native) object.wrapper_native_0x4084e38d (intptr,intptr,string,string)
09-27 11:22:36.810 E/mono-rt (20947): at (wrapper delegate-invoke) .invoke_intptr__this___intptr_intptr_string_string (intptr,intptr,string,string)
09-27 11:22:36.810 E/mono-rt (20947): at Android.Runtime.JNIEnv.GetMethodID (intptr,string,string) [0x00005] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/b76e8ec4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:118
09-27 11:22:36.810 E/mono-rt (20947): at Java.Lang.Throwable.get_Message () [0x00014] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/b76e8ec4/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Java.Lang.Throwable.cs:201
09-27 11:22:36.820 E/mono-rt (20947): at (wrapper runtime-invoke) .runtime_invoke_object__this__ (object,intptr,intptr,intptr)
09-27 11:22:36.820 E/mono-rt (20947): at <0xffffffff>
09-27 11:22:36.820 E/mono-rt (20947): at (wrapper dynamic-method) object.cca1eb61-76a3-412e-ae59-60429c7eb0b0 (intptr,intptr)
09-27 11:22:36.820 E/mono-rt (20947): at (wrapper native-to-managed) object.cca1eb61-76a3-412e-ae59-60429c7eb0b0 (intptr,intptr)
09-27 11:22:36.820 E/mono-rt (20947):
09-27 11:22:36.820 E/mono-rt (20947): =================================================================
09-27 11:22:36.820 E/mono-rt (20947): Got a SIGSEGV while executing native code. This usually indicates
09-27 11:22:36.820 E/mono-rt (20947): a fatal error in the mono runtime or one of the native libraries
09-27 11:22:36.820 E/mono-rt (20947): used by your application.
09-27 11:22:36.820 E/mono-rt (20947): =================================================================
09-27 11:22:36.820 E/mono-rt (20947):
Unhandled Exception:

Java.IO.IOException: Loading...
The program 'Mono' has exited with code 0 (0x0).`

Posts

  • rlangtonrlangton USMember ✭✭

    Attached the error for easier reading.

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    Hmmm Java.IO.IOException, but also SIGSEGV at the end. Any chance you can duplicate with a test project?

  • rlangtonrlangton USMember ✭✭

    I removed as many variables as I could. Set the project to Android 4.0 and greater so I wouldn't need Support libraries. Seems to still get the same error, or very similar (attaching error again).

    Also I thought this could be a permissions problem, but I copied permissions from the GCM tutorial.
    http://developer.android.com/google/gcm/client.html

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.wireco" android:versionCode="0" android:versionName="0.1"> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="com.wireco.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.wireco.C2D_MESSAGE" /> <application android:label="Wireco"> <receiver android:name=".GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.wireco" /> </intent-filter> </receiver> <service android:name=".GcmIntentService" /> </application> </manifest>

  • rlangtonrlangton USMember ✭✭

    I created a test project from scratch. It get's the same error. Anyone who can help please try it out.

    https://github.com/ryanlangton/GcmSample

  • rlangtonrlangton USMember ✭✭

    So I'm thinking this is likely a problem with the component and I should try doing my own binding. Is there any support for Components in the xamarin store so I can report this problem?

  • rlangtonrlangton USMember ✭✭
    edited October 2013

    I created a binding library to use instead of the Xamarin component. I'm still getting the same error but now I can see the code inside the Java library where it is crashing. It's this call to JNIEnv.GetString (line 172 of Android.Gms.Gcm.GoogleCloudMessaging).

    string __ret; if (GetType () == ThresholdType) __ret = JNIEnv.GetString (JNIEnv.CallObjectMethod (Handle, id_register_arrayLjava_lang_String_, new JValue (native_p0)), JniHandleOwnership.TransferLocalRef);

    So this is a problem with the Xamarin created binding right? I'm guessing because the binding and component were made by the same person, this part is just missing. I have no idea how to fix something like this, can anyone point me in the right direction?

    @topgenorth any ideas what is missing in the binding here?

  • rlangtonrlangton USMember ✭✭
    edited October 2013

    Finally got it working!! The problem was that I was calling the gcm.Register method from the main thread, which is not allowed. You'd think they could make the error more meaningful, and it's especially difficult when the error is buried in a Xamarin component. Using my own java binding library helped me to narrow down the problem, then this SO question helped.

    http://stackoverflow.com/questions/17721541/new-gcm-api-register-unknown-source-error

    Here is the code in my Activity that WORKS:
    ThreadPool.QueueUserWorkItem(o => { var gcm = GoogleCloudMessaging.GetInstance(this); var registrationId = gcm.Register("{mySenderId}"); });

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    Glad you got this working - I was beginning to worry that we had some kind of obscure error/bug with the Java bindings.

    FWIW, Google does mention (in one sentence in the middle of the their GCM tutorial) that gcm.Register and gcm.Unregister need to be called from a thread. Give the dire consequences of NOT performing this work in a thread, you'd think that they would have some stronger/easier to spot docs about this (and a better error message).

Sign In or Register to comment.