如何在VS代码上调试Cordova代码

问题描述 投票:0回答:1

我是Cordova和Android应用程序的新手。我们正在课堂上学习它,所以所有这些代码都是复制和粘贴的,目的是学习如何构建项目并在手机上运行它。

所以在calculator.js,calculator.css和index.html下面。

当我试图建立项目时,我一直在努力。

:app:generateDebugBuildConfig
FAILURE: Build failed with an exception.

FAILED
* What went wrong:
Execution failed for task ':app:generateDebugBuildConfig'.
> Failed to create C:\Users\mrgaw\Desktop\JS workspace\SWD106\MyCordovaApps\calculator\platforms\android\app\build\generated\source\buildConfig\debug\con\example\calculator

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

我得知有一些错误,因为项目没有建立。我没有得到的是出了什么问题。从来没有真正解释过如何调试这个,所以我实际上不太确定要调试代码的步骤。任何指针,提示或建议都会有所帮助。我基本上是想学习如何调试代码,这样我就可以学到什么错误。

function registerEventHandlers() {
  zero.addEventListener("click", buttonInputClickHandler, false);
  one.addEventListener("click", buttonInputClickHandler, false);
  two.addEventListener("click", buttonInputClickHandler, false);
  three.addEventListener("click", buttonInputClickHandler, false);
  four.addEventListener("click", buttonInputClickHandler, false);
  five.addEventListener("click", buttonInputClickHandler, false);
  six.addEventListener("click", buttonInputClickHandler, false);
  seven.addEventListener("click", buttonInputClickHandler, false);
  eight.addEventListener("click", buttonInputClickHandler, false);
  nine.addEventListener("click", buttonInputClickHandler, false);
  add.addEventListener("click", buttonInputClickHandler, false);
  subtract.addEventListener("click", buttonInputClickHandler, false);
  multiply.addEventListener("click", buttonInputClickHandler, false);
  divide.addEventListener("click", buttonInputClickHandler, false);
  point.addEventListener("click", buttonInputClickHandler, false);
  equals.addEventListener("click", buttonEqualsClickHandler, false);
  clear.addEventListener("click", buttonClearClickHandler, false);
}

// handle click event for buttons that enter and display input
function buttonInputClickHandler(eventArg) {
  var display = document.getElementById("display");
  display.value = display.value + eventArg.target.value;
}

// handle click event for equals button that evaluates and displays result
function buttonEqualsClickHandler(eventArg) {
  var display = document.getElementById("display");
  display.value = eval(display.value);
}

// handle click event for clearing display
function buttonClearClickHandler(eventArg) {
  var display = document.getElementById("display");
  display.value = "";
}
#calculator {
  display: block;
  width: auto;
  border: 2px solid black;
  padding: 5px;
}

#display {
  display: block;
  font-size: x-large;
  font-family: monospace;
  text-align: right;
  margin: auto;
  width: calc(100% - 10px);
}

.key {
  display: block;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  width: calc(25% - 10px);
  height: 100px;
  margin: 5px;
  background: yellow;
  float: left;
  font-size: x-large;
  font-family: monospace;
}

#equals {
  width: calc(100% - 10px);
}
<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">
  <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
  <link rel="stylesheet" type="text/css" href="css/index.css">
  <link rel="stylesheet" type="text/css" href="css/calculator.css">
  <title>Calculator</title>
</head>

<body onload="registerEventHandlers()">
  <div id="deviceready">
    <div id="calculator">
      <input type="text" id="display">
      <input class='key' type="button" id="seven" value="7">
      <input class='key' type="button" id="eight" value="8">
      <input class='key' type="button" id="nine" value="9">
      <input class='key' type="button" id="divide" value="/">
      <input class='key' type="button" id="four" value="4">
      <input class='key' type="button" id="five" value="5">
      <input class='key' type="button" id="six" value="6">
      <input class='key' type="button" id="multiply" value="*">
      <input class='key' type="button" id="one" value="1">
      <input class='key' type="button" id="two" value="2">
      <input class='key' type="button" id="three" value="3">
      <input class='key' type="button" id="subtract" value="-">
      <input class='key' type="button" id="zero" value="0">
      <input class='key' type="button" id="point" value=".">
      <input class='key' type="button" id="clear" value="Clear">
      <input class='key' type="button" id="add" value="+">
      <input class='key' type="button" id="equals" value="=">
    </div>
  </div>
  <script type="text/javascript" src="cordova.js"></script>
  <script type="text/javascript" src="js/index.js"></script>
  <script type="text/javascript" src="js/calculator.js"></script>
</body>

</html>
javascript html node.js visual-studio-cordova
1个回答
0
投票

你不“在VS代码上调试”。您可以使用Visual Studio 2017和Apache Cordova工具进行调试,或使用Chrome Remote Dubugging进行调试。看看Debugging Cordova Apps部分。如果您使用VS2017,您应该查看该站点或Microsoft TACO网站上的所有指南(更容易学习和开发)

enter image description here

请注意,无论JS文件中的错误数量如何,都将构建您的cordova应用程序,因为它们是不同的东西。如果应用程序构建但它自己关闭,那么你有JS错误,你必须在这种情况下使用Visual Studio或Chrome和模拟器或Android设备开始调试。

另外,我不会为Cordova应用程序使用带空格的路径。 Cordova可能比JAVA更容易,但是对于新手用户来说理解所有可能的问题会变得非常复杂,所以你必须首先阅读(更多)并编写更少的代码。

© www.soinside.com 2019 - 2024. All rights reserved.