Forum General

App working fine on adb debug, but crash after deploy apk to phone

sreccesrecce ARMember ✭✭
edited May 2016 in General

Hey Guys

(Not sure if this is the correct forum)

I'm newbie on xamarin, so I took the location example from the tutorials and changed a couple of things. Basically to still getting location on pause, and to connect to an api when location change.

It works fine when usb debugging using vs, and adb to my phone, but when I deploy the apk, and install on the same phone it crashes, with no error, just "Application has stopped" message.

I appreciate you help in advance to point me in the right direction.

Attached is the mainactivity.cs

Thanks

Best Answer

Answers

  • rmaciasrmacias USBeta, University ✭✭✭✭✭
    edited May 2016

    Use the Android Device Monitor with your phone plugged into your PC. You can monitor the output when you run your app. You don't need to launch it in the debugger, just start the app from the phone. In the LogCat, you should see the exception being reported when the app crashes. From Visual Studio go to Tools->Android->Android Device Monitor.

    https://developer.android.com/studio/profile/ddms.html

  • sreccesrecce ARMember ✭✭

    Thanks for your answer... I think I capture the error.

    Where I start searching?

    This is the output:

    06-01 00:44:40.431 E/AndroidRuntime( 2986): FATAL EXCEPTION: main
    06-01 00:44:40.431 E/AndroidRuntime( 2986): Process: Location.Droid, PID: 2986
    06-01 00:44:40.431 E/AndroidRuntime( 2986): java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): Caused by: java.lang.reflect.InvocationTargetException
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at java.lang.reflect.Method.invoke(Native Method)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at java.lang.reflect.Method.invoke(Method.java:372)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): ... 1 more
    06-01 00:44:40.431 E/AndroidRuntime( 2986): Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.Net.WebException: Error: NameResolutionFailure
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at System.Net.WebClient.UploadDataInternal (System.Uri address, System.String method, System.Byte[] data, System.Net.WebRequest& request) [0x000a6] in :0
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at System.Net.WebClient.UploadString (System.Uri address, System.String method, System.String data) [0x00054] in :0
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at System.Net.WebClient.UploadString (System.String address, System.String data) [0x00019] in :0
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at (wrapper remoting-invoke-with-check) System.Net.WebClient:UploadString (string,string)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at Location.Droid.Services.LocationService.OnLocationChanged (Android.Locations.Location location) [0x00157] in :0
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at Android.Locations.ILocationListenerInvoker.n_OnLocationChanged_Landroid_location_Location_ (IntPtr jnienv, IntPtr native__this, IntPtr native_location) [0x00011] in :0
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at (wrapper dynamic-method) System.Object:cad3edbb-2ed8-4cac-ad94-e74d5e046d4e (intptr,intptr,intptr)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at md5227b9e8295fbee87e0da67869d6e828e.LocationService.n_onLocationChanged(Native Method)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at md5227b9e8295fbee87e0da67869d6e828e.LocationService.onLocationChanged(LocationService.java:68)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:281)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:210)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:226)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at android.os.Handler.dispatchMessage(Handler.java:102)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at android.os.Looper.loop(Looper.java:135)
    06-01 00:44:40.431 E/AndroidRuntime( 2986): at android.app.ActivityThread.main(ActivityThread.java:5343)

  • rmaciasrmacias USBeta, University ✭✭✭✭✭

    So let's do some basic troubleshooting here. If you look at your stack trace, you can see the exception that caused the crash:

    Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.Net.WebException: Error: NameResolutionFailure

    This means that you're using some sort of HttpClient or WebClient to connect to an internet resource, and it can't connect to it because it either does not exist, can't find the address, or don't have an internet connection.

    If you look further down the stack trace, you can see it's coming from a WebClient.UploadString() method, that originates from a method called onLocationChanged().

    That's pretty much the information you need to look at your code and see what's going on. Looking at your code, I see this in your OnLocationChanged() method:

    using (WebClient client = new WebClient())
    {
         string json = "{\"imei\": \"" +  telephonyManager.DeviceId + "\", \"latitude\": \"" + location.Latitude.ToString() + "\", \"longitude\": \"" + location.Longitude.ToString() + "\",  \"address\": \"\",  \"datetracker\": \"2016-05-13T10:46:49.5135889-07:00\"}";
    
           try
    
              client.Headers[HttpRequestHeader.ContentType] = "application/json";
              string reply = client.UploadString("http://www.myapi.com/api/method", json);
    
              response.Text = reply;
    
    } 
    

    The exception is happening on your client.UploadString("http://www.myapi.com/api/method", json) call. I don't know if that web address is something you made up in order to protect your real URL or not, but that web address doesn't exist. Whatever the web address is, make sure your phone (whether connect to LTE or Wifi) has access to that URL.

    On another note. Your code is filled with syntax errors that should not compile. I'm not sure if you sanitized it or have copy/paste errors, but it's usually a good idea to make sure it's proper syntax before you post.

Sign In or Register to comment.