Search code examples
androiddebuggingandroid-studiousbadb

Unable to debug application over USB; works with emulator


Android Studio on Windows - Following successful Gradle sync and build, I am unable to launch my application on my (rooted) Android Galaxy S3 and debug via USB. I have USB Debugging enabled on my device.

I am able to:

  • provision and debug via the debug interface on the emulator
  • see my USB device in the Android DDMS window:

    DDMS Window - Device Connected

  • manually provision via adb, then connect via the debugger, using the same commands that come out of the debug window in Android Studio:


Cd "C:\Program Files (x86)\Android\android-studio\sdk\platform-tools"
adb -d shell 
su
pm uninstall com.company.myapplication
ls -all /data/app | grep myapplication
pm install -r "/data/local/tmp/com.company.myapplication"
am start -n "com.company.myapplication/com.company.myapplication.MapsActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

  • Following manual provisioning (see above), I can attach to the running process on my device, and debug (including hitting breakpoints):

    Android Choose Process

  • Select my device from the "Choose Device" window when attempting to initiate USB debugging:

    Choose Device - physical device present

    ... following which I get the following output (and no activity on the Android device UI):


Waiting for device. 
Target device: samsung-sgh_t999-6XXXXXX2
Uploading file
    local path: D:\Data\XXXXXX\Sandpit\XXXXXX\MyApplication\app\build\outputs\apk\app-debug.apk
    remote path: /data/local/tmp/com.company.myapplication
Installing com.company.myapplication
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.company.myapplication"`

Launching application: com.company.myapplication/com.company.myapplication.MapsActivity.
DEVICE SHELL COMMAND: am start -D -n "com.company.myapplication/com.company.myapplication.MapsActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Waiting for process: com.company.myapplication  

In the case above, after checking files using the adb shell, I have noticed that the pm install command works -- i.e. there's an updated file (based on timestamp) in location /data/local/tmp/com.company.myapplication. However, the am start doesn't work, as the .apk file under

I have tried:-

  • Restarting the computer
  • Restarting the Android device
  • Reinstalling Android Studio
  • Run app (rather than Debug app): same result, no app installation on Android device
  • Creating a new test application to see whether it's a problem with Gradle or Manifest configuration problems in my original application.
  • Cleaning the project
  • Connecting as both a Media device (MTP), and also as Camera (PTP)
  • Enabling mock locations (Settings -> Developer options -> Allow mock locations)
  • Adding android:debuggable="true" to the Android Manifest XML (<appRoot>\MyApplication\app\src\main\AndroidManifest.xml), despite IDE suggestion to the contrary: android:debuggable attribute

  • Ensuring ADB Integration is enabled:

    ADB Integration Setting

  • Toggling the ADB connection on the phone (Settings -> Developer Options -> USB Debugging check/uncheck/recheck, reconnect)

  • Updating to the latest Samsung drivers for the S3 - downloaded, refreshed in Windows Device Manager:

Samsung ADB Device in Device Manager

  • Restarting the ADB Server, including as root, then re-connecting (and subsequently re-attempting debugging from Android Studio over USB):

C:\Program Files (x86)\Android\android-studio\sdk\platform-tools>adb wait-for-device

C:\Program Files (x86)\Android\android-studio\sdk\platform-tools>adb devices
List of devices attached
6XXXXXX2        device


C:\Program Files (x86)\Android\android-studio\sdk\platform-tools>adb root

C:\Program Files (x86)\Android\android-studio\sdk\platform-tools>adb kill-server

C:\Program Files (x86)\Android\android-studio\sdk\platform-tools>adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *

C:\Program Files (x86)\Android\android-studio\sdk\platform-tools>adb wait-for-device

C:\Program Files (x86)\Android\android-studio\sdk\platform-tools>adb devices
List of devices attached
6XXXXXX2        device


C:\Program Files (x86)\Android\android-studio\sdk\platform-tools>

Versions:-

  • I had Android Studio v0.8.2, but as part of my testing efforts have since downgraded to 0.8.1, which also doesn't work (same problem).
  • Cell phone is SGH-T999, Android version 4.1.2
  • OS is Windows 7 Enterprise SP1

    What have I omitted? What else should I try?


Solution

  • Just to provide closure... I ended up dropping this device, and it wasn't worth repairing the screen, so this device no longer exists. My new device - also an S3 - works after being rooted.