Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app debugs for a few seconds then just stops

I'm trying to set up a new Android app development environment at home and I've run into a problem that is a showstopper.

First, here is my environment:

  1. Windows 10
  2. Visual Studio Community 2015 with Xamarin platform installed
  3. Test device is: G Pad 7.0 LTE
  4. Android Version 5.0.2

I'm following this tutorial: MSDN tutorial

When I go to debug my test app, here is what happens.

  • Select debug from Visual Studio with my tablet as the target
  • VS deploys to the tablet
  • App starts on the tablet
  • App and debug session runs for about 5-10 seconds.
  • Debug session ends and app closes

No errors are displayed in Visual Studio and when i turn on Android logging it's a such a massive overflow of information that I don't really know where to begin searching for a problem.

Please also note that when I first set up the app, according to the tutorial, debugging on the tablet worked fine. The initial build is simply a template with a few basic controls.

In between then and when it stopped working I also added and successfully tested a Windows Phone project on a Windows Phone device.

Once I got to the section where I was modifying the project is when the problem started. I thought that perhaps a change in the code I did caused this issue so I tried another blank app and that blank app now crashes as well.

When I deploy the tutorial app to an emulator it crashes immediately but when I deploy a blank app it doesn't crash.

I also tried restoring the tablet to factory defaults and testing again. Same scenario: Blank app and tutorial app run for a few seconds, debugging stops, app closes.

Any clue as to what type of problem I'm looking at?

like image 727
Minsc Avatar asked May 01 '16 20:05

Minsc


People also ask

What does debug level do on Android?

Debug mode enables you to see logs of various Tapjoy actions (sessions, placements, purchases, custom events, etc. ). These will appear in the Tapjoy Developer Console. To get to the developer console, go to the wrench icon in the top navigation bar of the dashboard and select "Developer Console" from the drop down.

How do I enable debug on APK?

To start debugging an APK, click Profile or debug APK from the Android Studio Welcome screen. Or, if you already have a project open, click File > Profile or Debug APK from the menu bar. In the next dialog window, select the APK you want to import into Android Studio and click OK.


2 Answers

What fixed it for me in Visual Studio 2017 is going to :

Tools → Options → Xamarin → Android Settings

and uncheck:

Preserve Application data cache on device between deploys

like image 75
user2282900 Avatar answered Oct 24 '22 07:10

user2282900


Solution

  1. Clean your project (Right-Click on Project and select clean)
  2. Go to your build folder. Probably in your Android project's root folder, named "obj". Delete either build you had, when you ran into this behavior (Debug or Release).

Directory Path

./AndroidProject/obj/Debug
./AndroidProject/obj/Release
  1. Restart Visual Studio
  2. Build and run again and it should work just fine, as the md5-hashes are now matching again.

I had also uninstalled the app before from the device and restarted it, I don't know whether this is required anymore, because the app is now being "reinstalled" by newer Xamarin versions anyway.

adb uninstall com.your.domain

Story and Background information

Have had the same issue with a device running Android 5.0.

Basically, the app was just stopping without any note. When I now restarted the phone, The log was extended (once) by the following line:

Device could not find component named: *com.your.domain*/{*md5hash*}.*{Activity}

It turns out that with Andrpod 5.0 a hashing mechanism was implemented:

With the 5.0 release, the default package names for Android Callable Wrappers will be based on the MD5SUM of the assembly-qualified name of the type being exported. This allows the same fully-qualified name to be provided from two different assemblies and not get a packaging error. See this for further information Xamarin.Android 5.1

So, if the md5-hash now changes from time to time, a simple Clean of your project is not enough.

like image 37
Lepidopteron Avatar answered Oct 24 '22 07:10

Lepidopteron