Phonegap应用程序的Android远程调试不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22206816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:38:21  来源:igfitidea点击:

Android remote debugging for Phonegap app does not work

androidgoogle-chromecordovagoogle-chrome-devtoolsremote-debugging

提问by Javier Hertfelder

Hi I am trying to debug my phonegap app on my device via Chrome I have followed all the stepsand my phone is recognized by adb devices command,

嗨,我正在尝试通过 Chrome 在我的设备上调试我的 phonegap 应用程序我已按照所有步骤进行操作,并且我的手机已被 adb devices 命令识别,

Then I go to chrome://inspect/#devices and I can see my phone but this message appears on the browser:

然后我转到 chrome://inspect/#devices,我可以看到我的手机,但浏览器上会出现此消息:

Offline

离线

0019C9AD7EF31F

0019C9AD7EF31F

Pending authentication: please accept debugging session on the device.

待验证:请接受设备上的调试会话。

The thing is that there is no such message in my phone, I have a Sansumg Galaxy S2 with kitkat. I updated the version from 4.1 to 4.4 because I thought that was the issue but after updgrading to 4.4 same problem.

问题是我的手机中没有这样的消息,我有一个带有 kitkat 的 Sansumg Galaxy S2。我将版本从 4.1 更新到 4.4,因为我认为这是问题但在升级到 4.4 之后同样的问题。

Has anyone faced this problem before??

以前有人遇到过这个问题吗??

回答by aharris88

The problem is that remote debugging used to only work for the Chrome browser on Android, but not in webviews inside of apps like phonegap uses. But with Android 4.4 (Kitkat) and Phonegap 3.3, this is now supported.

问题是远程调试过去只适用于 Android 上的 Chrome 浏览器,但不适用于 phonegap 等应用程序内部的 webviews。但是现在支持 Android 4.4 (Kitkat) 和 Phonegap 3.3。

I wrote a blog post about it here:

我在这里写了一篇关于它的博客文章:

http://adamwadeharris.com/remote-debugging-in-phonegap-with-chrome-devtools/

http://adamwadeharris.com/remote-debugging-in-phonegap-with-chrome-devtools/

Basically you need to enable webview debugging in the app's main Java file, and make sure your app is targeting API version 19 (Kitkat). If you don't have a device with Kitkat, you could use an emulator instead.

基本上,您需要在应用程序的主 Java 文件中启用 webview 调试,并确保您的应用程序面向 API 版本 19 (Kitkat)。如果您没有带有 Kitkat 的设备,则可以改用模拟器。

Here's how you enable webview debugging:

以下是启用 webview 调试的方法:

In platforms/android/src/com/yourAppName/YourAppName.java add the following lines under the other import statements

在platforms/android/src/com/yourAppName/YourAppName.java 中,在其他导入语句下添加以下几行

import android.os.Build;
import android.webkit.WebView;

And add the following inside the onCreate method:

并在 onCreate 方法中添加以下内容:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  WebView.setWebContentsDebuggingEnabled(true);
}

回答by bjunix

As it is already said in some comments, this is working out of the box since cordova 3.3+ and android 4.4+. You do not need to set anything in the AndroidManifest.xml.

正如一些评论中已经说过的那样,自cordova 3.3+和android 4.4+以来,这是开箱即用的。您不需要在 AndroidManifest.xml 中设置任何内容。

If you use cordova buildor cordova runthe default build mode will be "debug". You can see this also in the generated apk file name which will look like:

如果使用cordova buildcordova run默认构建模式将是“调试”。您也可以在生成的 apk 文件名中看到这一点,如下所示:

{app_name}-debug-unaligned.apk

{app_name}-debug-unaligned.apk

In this case you just need Chrome in Version 32+ and select Chrome menu > Tools > Inspect Devices(of course after you deployed the app to your device and turned on usb debugging).

在这种情况下,您只需要版本 32+ 的 Chrome 并选择Chrome menu > Tools > Inspect Devices(当然在您将应用程序部署到您的设备并打开 USB 调试之后)。

For additional info look also here: https://developer.chrome.com/devtools/docs/remote-debugging

有关其他信息,请参见此处:https: //developer.chrome.com/devtools/docs/remote-debugging

Concerning the authentication problem... When you first run cordova android runyour app will be deployed to your phone and you need to confirm the authentication dialog and make a tick to remember your choice. After this you should be good to inspect the deployed app in the chrome inspector.

关于身份验证问题...当您第一次运行时,cordova android run您的应用程序将部署到您的手机,您需要确认身份验证对话框并勾选以记住您的选择。在此之后,您应该可以在 chrome 检查器中检查已部署的应用程序。

回答by Miao1007

It seems to be a bug on the phone. I fixed by doing:

这似乎是电话上的错误。我通过以下方式修复:

  1. Select Developer options
  2. Revoke USB debugging authorized
  3. turn off and on the USB debugging switch
  4. connect to your PC
  5. now, just accept the two authority dialog, and it will work fine in AndroidStudio and Chrome.
  1. 选择开发者选项
  2. 撤销USB调试授权
  3. 关闭和打开USB调试开关
  4. 连接到您的 PC
  5. 现在,只需接受两个权限对话框,它就可以在 AndroidStudio 和 Chrome 中正常工作。

回答by Baidaly

If you see "Pending authorization" keeps flashing try to remove all Chrome updates from the device and downgrade to Chrome v.33. Seems something got broken in one of the latest Chrome builds(got the problem with Chrome v.44). Here is the link to the related issue: https://code.google.com/p/chromium/issues/detail?id=512150

如果您看到“待授权”不断闪烁,请尝试从设备中删除所有 Chrome 更新并降级到 Chrome v.33。似乎在最新的 Chrome 版本之一中出现了问题(Chrome v.44 有问题)。这是相关问题的链接:https: //code.google.com/p/chromium/issues/detail?id=512150

回答by brunettdan

If you're using Phonegap Build, add the following to your config.xml to be able to inspect the webview in the Chrome dev console.

如果您使用 Phonegap Build,请将以下内容添加到您的 config.xml 中,以便能够在 Chrome 开发控制台中检查 webview。

First, make sure your widget tag contains xmlns:android="http://schemas.android.com/apk/res/android"

首先,确保您的小部件标签包含 xmlns:android="http://schemas.android.com/apk/res/android"

<widget 
    xmlns="http://www.w3.org/ns/widgets" 
    xmlns:gap="http://phonegap.com/ns/1.0" 
    xmlns:android="http://schemas.android.com/apk/res/android"
    id="me.app.id" 
    version="1.0.0">

Then add the following

然后添加以下内容

<gap:config-file platform="android" parent="/manifest">
     <application android:debuggable="true" />
</gap:config-file>

It works for me on Nexus 5, Phonegap 3.7.0.

它适用于我的 Nexus 5,Phonegap 3.7.0。

<preference name="phonegap-version" value="3.7.0" />

Source: https://www.genuitec.com/products/gapdebug/learning-center/configuration/

来源:https: //www.genuitec.com/products/gapdebug/learning-center/configuration/

回答by Emperorlou

Here is another solution that might work for some people

这是另一种可能适用于某些人的解决方案

A long time ago I had setup the certificate signing with Phonegap Build and because of that it was automatically generating "release" versions of my app. It was so long ago I had forgotten about this little detail.

很久以前,我使用 Phonegap Build 设置了证书签名,因此它会自动生成我的应用程序的“发布”版本。很久以前,我已经忘记了这个小细节。

To get it to give you a debug version of the app you have to specifically choose No key selectedin the dropdown for android on the Phonegap Build page. Then when you download the apk it generates, it will have appname-debug.apk instead of appname-release.apk.

要让它为您提供应用程序的调试版本,您必须在 Phonegap Build 页面上的 android 下拉列表中专门选择No key selected。然后当你下载它生成的 apk 时,它会有 appname-debug.apk 而不是 appname-release.apk。

回答by user3924365

This is nice for me:

这对我来说很好:

adb logcat CordovaActivity:V CordovaLog:V Cm
CordovaWebView:V IceCreamCordovaWebViewClient:V *:S