Debugging Cordova App (android) with Visual Studio 2015 New Emulator

给你一囗甜甜゛ 提交于 2020-01-23 00:26:08

问题


I am not sure if this is me doing something stupid or just up against the bleeding edge.. I am developing a simple Cordova app but that is academic since I can repeat this issue with the standard 'Wizzard produced' default application.

I had the app working and debugging fine with VS2013 using both Ripple and occasionally with a real device. I don't have permanent access to the device so I thought Id try the new VS2015 CTP5 with emulator. So far so good. All builds ok and the app does get deployed to the emulator, and starts. However, VS is stuck in the 'deploying' process and never comes out. To the extent that I have to 'ctrl-Break' out of it. and the debugger never starts.. The last few lines of the build output are:

2>  Built the following apk(s):
2>      C:\Users\Brett\Documents\VisualStudioCordova\Projects\mblapp\mblapp\bld\Debug\platforms\android\ant-build\CordovaApp-debug.apk
2>  Using apk: `C:\Users\Brett\Documents\VisualStudioCordova\Projects\mblapp\mblapp\bld\Debug\platforms`\android\ant-build\CordovaApp-debug.apk
2>  Installing app on device...
2>  Launching application...
2>  LAUNCH SUCCESS
2>  Command finished with error code 0: `C:\Users\Brett\Documents\VisualStudioCordova\Projects\mblapp\mblapp\bld\Debug\platforms`\android\cordova\run.bat --nobuild,--target=169.254.138.177:5555,--debug
2>  

So there is an error there but I really don't get what it means..

Ok, So I went back to VS2013 but now the 2015 install has changed something and using Ripple it now breaks out of the code at unexpected places in the code.. not breakpoints.. and the javascript console says 'Paused at breakpoint' in its dropdown. I cant access the 2015 Emulator directly, but out of interest I left the emulator running after 2015 was closed and CAN connect AND debug using VS 2013.. great.. but its not a great way to start debugging..

I really like the look of the new Emulator and it does seem to work great with 2013.. so does anyone out there know how to make VS2013 deploy to the new emulator? .. I tried running it and did have some success. But I cant find where VS2015 has hidden its VHD file..

Or, does anyone know why VS2015 might not be deploying correctly.. Im happy to go with a solution that works.. Just that right now Im stuck not going forward, and its an uninstall 2015 and probable reinstall 2013 to go back... Many thanks.


回答1:


OK.. Ive posted this as an answer because it does deal with part of it.. and I did struggle a bit so it might help someone else. Running the emulator from VS2013. You need to go to the folder

C:\Program Files (x86)\Microsoft Visual Studio Emulator for Android\1.0

where the emulator is installed. Having run it at least once from VS2015, it had created a file called vsemu.vhd and vsemu.sdcard.vhd. Copy both these files to something similar in the same folder I used 'myemu'. Then to start the emulator I created a simple shortcut with the target property:

"C:\Program Files (x86)\Microsoft Visual Studio Emulator for Android\1.0\XDE.exe" /vhd bretts.vhd /video 1080x1920

this sets the resolution too.. You can find all the startup flags etc by using:

...XDE /?

Im not sure yet, but I think it stored the various app shortcuts in the sdcard file.. although I wouldn't swear to it. Ill repost if something changes there.

Ok Debugging.. I started VS2013 and set the debug target as 'Device'. This worked fine.. so far.

Id still love to know why 2015 is not deploying properly though, for now I'll just assume its the 'bleeding' part of the bleeding edge. Cheers




回答2:


There is a known issue in Visual Studio 2015 CTP5 with Cordova projects deploying to the Visual Studio Emulator for Android. The issue will be resolved in the next release.

In the meantime, here are a few workarounds to try:

  1. Search your machine for Microsoft.VisualStudio.MultiDeviceHybridApps.dll. There will be two copies--one under "Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Emulator for Android\" (the VS Emulator version of the dll) and one in another folder under "Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\" (the folder name varies, but it is always some random hash; this is the Cordova version of the dll). Close out of VS2015 and replace the Microsoft.VisualStudio.MultiDeviceHybridApps.dll in the Emulator for Android folder with the one in the Cordova folder (delete the Emulator one, copy the Cordova one, and paste it in the Emulator folder). Then go to "C:\Users\your username\AppData\Local\Microsoft\VisualStudio\14.0\Extensions" and delete the contents of this folder.

  2. Create a new Visual C++ Native-Activity Application (File > New > Project, under Installed\Templates\Visual C++\Cross Platform\Native-Activity Application (Android)) and run it, then return to your Cordova project.

  3. Reinstall CTP5 and the Visual Studio Emulator for Android and reinstall.

Hope this helps!




回答3:


Another workaround for webkit developers (Android and iOS), the Chrome remote debugger, check out here.

With this you can debug as you would do normally, this does work with the emulators of vs2015 ctp5!



来源:https://stackoverflow.com/questions/28239195/debugging-cordova-app-android-with-visual-studio-2015-new-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!