16

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

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

Offline

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.

Has anyone faced this problem before??

1
  • have you activated your phone for development? Mar 5, 2014 at 19:38

7 Answers 7

17

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.

I wrote a blog post about it here:

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.

Here's how you enable webview debugging:

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

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

And add the following inside the onCreate method:

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

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.

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

{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).

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

Concerning the authentication problem... When you first run cordova android run your 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.

2
  • 1
    ... I've never seen an authentication dialog for android ? should that be on your pc, where you are building, or on your device ?
    – commonpike
    Jan 30, 2015 at 16:19
  • @commonpike The authentication dialog will appear on the device itself.
    – flyingace
    Mar 1, 2015 at 4:27
4

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.
2

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

2

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.

First, make sure your widget tag contains 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.

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

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

2

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.

To get it to give you a debug version of the app you have to specifically choose No key selected in 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.

-1

This is nice for me:

adb logcat CordovaActivity:V CordovaLog:V Cm
CordovaWebView:V IceCreamCordovaWebViewClient:V *:S
1
  • 1
    Not sure your answer provides enough details... but I don't know much about android dev Aug 9, 2014 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.