Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android remote debugging for Phonegap app does not work

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??

like image 548
Javier Hertfelder Avatar asked Mar 05 '14 19:03

Javier Hertfelder


People also ask

How do I debug Cordova app in emulator?

Connect your phone to your computer with USB. On your device, an alert prompts you to allow USB debugging from your computer. Tap OK. Launch your cordova App by running cordova run android or installing the app with adb ( adb -d install -r platforms/android/build/outputs/apk/android-debug.


1 Answers

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);
}
like image 150
aharris88 Avatar answered Sep 28 '22 01:09

aharris88