Android app debugs for a few seconds then just stops - c#

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:
Windows 10
Visual Studio Community 2015 with Xamarin platform installed
Test device is: G Pad 7.0 LTE
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?

Solution
Clean your project (Right-Click on Project and select clean)
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
Restart Visual Studio
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.

I ran into this same issue and applied the same solution described above many times, which seemed to remedy this particular problem.
A possibly related fix, but definitely worthwhile note
After releasing this Android app and later releasing updates to the app, we got feedback from users that their Android Home screen shortcut to the app was disappearing after each app update. This is not good, for obvious reasons, but the fix for it was very simple as noted here:
dream-team-mobile-blog - Android app removes shortcut on update Xamarin solution
On the main activity, set a Name attribute of
<your package>.<your main activity>
like:
com.mycompany.myapp.MainActivity
For my solution, I chose to do it in code like this:
[Activity(Name = Constants.PackageName + "." + nameof(MainActivity),
Label = Constants.AppIconTitle, Icon = "#drawable/icon",
Theme = "#style/splashscreen", MainLauncher = true,
LaunchMode = LaunchMode.SingleInstance,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
//Side Note: I change my PackageName between Prod and SQA builds, so using
//a constant as seen above makes that change less risky to miss maintaining.
//Also, using nameof() keeps things tight and a sure match.
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
I mention it here in this post because, having this fix in place may have:
definitely prevented app shortcut loss and
possibly prevented the issue discussed in this post
as the MD5 hash prefix from the Main activity seems to no longer be generated.
This tweak may fix two bugs with one fix. If not, implementing a fixed main Activity Name will surely help your users keep their shortcut to your app when you release updates!

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

go to your AndroidManifest.xml and change your package name.

Related

This error is preventing me from building my UWP app on a new Xamarin Form project

I'm beginning my first Xamarin project. I started with setting up an android project and I have gotten it working with the emulator.
But after following the instructions of this video
(https://www.youtube.com/watch?v=mbIvG8ripcw&t=590s&ab_channel=GeraldVersluis)
I get the following error when I try to build:
Expected "!$([System.String]::new('%(ReferenceCopyLocalPaths.Identity)').EndsWith('System.Runtime.dll'))" to evaluate to a boolean instead of "!$([System.String]::new('E:\(PATH TO APP FOLDER)\Notes App\NotesApp\NotesApp\bin\Debug\netstandard2.0\NotesApp.dll').EndsWith('System.Runtime.dll'))", in condition "'$(_CoreFrameworkPackageId)' != ''
AND !$([System.String]::new('%(ReferenceCopyLocalPaths.Identity)').EndsWith('System.Runtime.dll'))
AND '%(ReferenceCopyLocalPaths.NuGetPackageId)' == '$(_CoreFrameworkPackageId)'". NotesApp.UWP
^^ The error code I get for this is MSB4100
I also keep having the Nuget packages Xamarin.Forms and the Microsoft.NETCore.UniversalWindowsPlatform go missing from the references of my project even though they are installed within it. After restarting VS multiple times and toggling on/off settings that alters the project/solution heavily they pop back into existance.
These packages when they go missing give me 10s and I even saw once, 200 errors and they all disappear after turning on and then off again, for example "Compile with .NET Native tool chain" in the build settings.
But the big error above still remains.
========================================
All Nuget packages are up to date and VS is up to date (and I used the repair tool).
I've removed the UWP project and created a new one, and I get the same result.
If anyone can help me solve this and let me know if I've made a silly mistake it would be appreciated. I would like to master this.
If you need any more info let me know, thanks.
Update 1
I've reinstalled my nuget packages and restarted VS and this is my screen. Note I have the package on screen installed but not showing up in my references. Plus some warnings that go away when they feel like it.
Update 2
I created a brand new xamarin android and uwp project template, did not touch a thing, and I tried to build and deploy the uwp project and I get this error
I created a project that was not buring by many layers of folders, in my C drive and not my external exFAT E drive and it now works.
Thanks for your help guys.

Xamarin.Android.Common.Debugging.targets(604,5): error XA0010: No available device

Whenever I try to start the HelloMaui project from VS Code using NET 6.0.100 Preview4 with mono debug extension installed and run it it throws an error Xamarin.Android.Common.Debugging.targets(604,5): error XA0010: No available device. I wonder if anyone had a problem running the sample project?
The same bug has been reported 3 days ago in the official repo https://github.com/dotnet/maui/issues/1197, as MAUI still in an early stage it better to follow on the official repo.
Try to ensure that the emulator is ready before debugging the app (build+deploy), by starting it manually.
Not sure how to do it from vs code but probably will be common for command line:
Navigate to C:\*\Android\android-sdk\emulator
emulator -list-avds
You should see at least one emulator name otherwise you need to install one.
emulator.exe -avd NameOfYourEmulator -partition-size 512 NameOfYourEmulator taken from the previous step.
Docs
https://learn.microsoft.com/en-us/xamarin/android/deploy-test/command-line-emulator
Edit
If the returned list of Android device emulators is empty (from step 2) and you are sure you have at least one emulator previously added/installed then try unloading and reloading the android project.
If you are not sure, you may open Android device manager from visual studio and check the listed devices there, if empty then you need to add at least one.
Related issue Maui-check fails on Android Emulator Setup

Avoiding Xamarin app "collision" when debugging

The root of the problem is perfectly explained here (mind you, my question is different from what can be found in this post): Xamarin - Android - Visual Studio - The application could not be started
In my particular case:
Debug from PC1: everything OK
Debug from PC2 without uninstalling debug app from PC1: the error appears for the first time
Try everything to avoid this error. The app cannot be found in the phone, I deleted the files manually as one post suggested (this might have been a mistake). No "myAppName" files can be found in my phone.
So I have decided to trick Android into thinking it is a different app, and this is what my question is about.
I have changed everything I found in the project (namespace, blah blah) from "myAppName" to "slightlyDifferentAppName" but the problem persists... I have debugged different projects form PC2 and they work, which makes me think it is a "collision" between different signatures of the same app (because otherwise it makes no sense that it worked in PC1 and not in PC2).
My question is: what can I tweak in Visual Studio in order to trick Android into thinking it is a different app?

Windows Phone 8 SDK doesn't refresh XAML part of a page

I'm working on an app for Windows Phone 8 and I'm debugging it on my Nokia Lumia 925. But every time I press F5, the XAML code stays the same while my c# code refreshes - so I've got the new code, but the UI is the same. I have to reinstall the app every time to get the changes on my phone.
Any ideas how I could fix that? Thanks!
Each time you debug, make sure to first Rebuild the app. Also you may encounter issues such as "Symbols not loaded" from the ".pdb" extension in your debug folder. In that case you can do two things to resolve the issue:
Goto your project's Bin/Debugfolder and delete all the items.
Or just do Clean Solution each time before you debug the app.
In this way, you can deploy the most updated version of your code into your Emulator/Device and avoid any missing symbols errors. Hope that helps.

VS 2012 Debugger hangs when I try to quick watch variables

I've come across an extremly annoying bug this afternoon. I've been working casually on console application I'm working on for a while now and for no reason at all the VS2012 debugger started hanging when I quickwatch any variables. It hangs for like 15-20 seconds, then I get the message
Function evaluation is disabled because a previous function evaluation timed out
If i then hit F10, the debugger unattach and the process goes on. It crashes on almost every variables that are implicitly declared
Here's the steps I have taken so far to resolve this problem.
Steps I have taken:
Restart VS
Reboot computer
Deleted all breakpoints
Deleted ncb and suo file
Symbol Server is not enabled
No Network location is used, User files are local, project files are
local.
Just My Code enabled/disabled
Ensured Enable .NET Framework source stepping is NOT enabled
Ensured Step over properties is enabled
Ensured Enable source server support is not enabled
Start visual studio with /SafeMode to suppress extensions
Cleared Watch Window (was empty anyway)
Tried changing target platform to x64 and any CPU
Disabling antivius
Resetting visual studio default settings(devenv.exe /ResetSettings)
Reinstall VS
The application I'm debugging :
Type : C# Console application
Target Framework: 3.5
Platform target: x86
For my health sake, please help.
EDIT : I have Visual Studio Update 3, version 11.0.60610.01
EDIT: My computer specs
Windows 7 Ultimate 64 bits
Dell Optiplex 960
Intel Core i5-2400 3.1 Ghz
4 GB RAM
EDIT : I tested on two machines (same code) without visual studio update 3 one that does work, one that does not.
EDIT: A created a simplified console application with the same settings that contains only the following lines of code. I'm getting the hang problem when I watch and then it unattach also. What could be wrong with my machine?
This is a simplified application that hangs the debugger
static void Main(string[] args)
{
var _AppLocation = System.Reflection.Assembly.GetEntryAssembly().Location;
_AppLocation = _AppLocation.Substring(0, (_AppLocation.Length -
(System.Reflection.Assembly.GetEntryAssembly().GetName().Name.Length + 5)));
var directoryInfo = new DirectoryInfo(_AppLocation);
Console.ReadyKey(); //I break here, check the directoryinfo
}
EDIT 10/3/13: This is still unresolved, reinstalling everything(office,framework,vs) completly did not solve the problem. It must be a vs2012 bug that is os/hardware related. I will open a ticket at Microsoft and update if they find out something usefull.
EDIT 10/30/13: This problem have been reproduced on two machines with different hardware configuration. I'm still in contact with microsoft to find the issue. Looks like something related to the framework/windows build/visual studio.
EDIT 11/19/13: I'm still in contact with Microsoft VS escalation team, here's the process monitor log and visual studio crash dump of the problem. http://sdrv.ms/1egpX4O
Solution found in parallelle with the Microsoft VS Escalation team. After analysing the crash dump and process monitor it seems that VS 2012 debugger process checks the store certificate for the Microsoft Root Authority certificate.
Since both computers where in a protected no internet environment, both of them never had been connected online. Thus, they never downloaded the Microsoft CA. Since the CA was absent from the store, it caused the debugger to hang and crash for 3.5 target framework specificly.
Here's the fix from Microsoft VS Team to bypass this check when debugging: (Add in the application app.config)
<configuration>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
Problem resolved!
I had this same problem with Visual Studio 2015 (including Update 1 and Update 2). So posting my solution (which I submitted to MS) in case somebody else has this problem.
Whenever I tried to use QuickWatch in Visual Studio 2015 Enterprise it would hang the development environment. I can’t click on anything and I’m forced to kill the process via Task Manager. It seems like the modal window opens behind it.
My computer is an HP Spectre and I have another monitor plugged in. I’ve tried it on both monitors.
The fix was to:
Switch to a single monitor
Make the QuickWatch open (which it does)
Move it around (which must
save the window position)
Close it
Plug second monitor in
Now when I use the QuickWatch, it will open correctly
Consider using Process Monitor tool to get a log of file, network, registry and processes operations happen during your investigation. After capturing the log, you may see through it and investigate the possible reason. Or, you can send your log to me and I will investigate it on my side
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
I have done a quick research on msdn and found this :
http://social.msdn.microsoft.com/Forums/vstudio/en-US/2055d3a0-56d9-4134-be23-09a91203e508/quickwatch-says-the-following-for-all-evaluations-function-evaluation-disabled-because-a-previous
Please try the following suggestions to check the result:
Click Tools | Options.. | Debugging | General, and uncheck "Enable
property evaluation and other implicit function calls" option. Step
into (F11) the code to find the root cause of the "time out" Restart
debugging
For more information on the Function Evaluation error, please refer
to: http://msdn.microsoft.com/en-us/library/ms234762(VS.80).aspx
Also, we could get more workarounds of Function Evaluation at blog:
http://blogs.msdn.com/greggm/archive/2005/11/18/494648.aspx
Also it may sound weird but have you the latest update of visual studio 2012?
I had some similar issues when running VS2012 with UAC(User Account Control) turned on, and when having installed some extensions, VisualStudio binds to the running w3p.exe process which works as expected under 1 worker process. Upon allowing multiple worker processes to exist studio cannot track all the independent threads and chokes on the data which reads as corrupted memory.
For myself I have the save setup has yours except for the x64 bit. This always gave me headache in programming... Visual Stutio is 32 bit as long as i know and there is surely a reason why... Anyway you sample work and no hang happend... I cannot tell you exactly why it happened but i'm sure it's a 64 bits related environment of development.
I tried provided code.
VS2012 Ultimate works fine on debug settings and on release setting.
I tested on two differents PCs (desktop and surface Pro)
I also forced x86 setting instead of AnyCPU.
Here is my output for the test application :
http://beehiver.jurion.me/debug%20working.png
I recomend complete uninstall all VS and ALL versions of .net and reinstall. It seems to be a problem on your laptop.
I had the same problem. I suppose its more to do with the hardware configuration. I recently upgraded from 4GB ram to 8GB with Vs 2012 and have never been able to replicate the problem. I used to consistently get this error with the earlier Hardware config.
This Problem happens when your code is waiting for some previous threads to finish there execution,also try to delete .suo file then restart visual studio
This may be related Console.ReadKey() problems/bugs.
http://blogs.microsoft.co.il/blogs/dorony/archive/2012/09/12/console-readkey-net-4-5-changes-may-deadlock-your-system.aspx
Does the problems persist if you use a different method of "pausing?"
There are also some disadvantages of VS. For example, if you open two VS at the same time, while you are writing code, it sometimes get into no response and showing "Saving auto recovery Infomation"

Categories