[android] Not Able To Debug App In Android Studio

I am making an app in Android Studio, now trying to debug it through adb. When I click on the word Android and the logo on the bottom bar, logcat comes up and recognizes my device. Then I see this:

screenshot

What do I need to do to my app to make it "debuggable"?

FYI was developing this app in Eclipse before and adb worked fine.

This question is related to android debugging adb android-studio

The answer is


One case where you can be unable to debug an application in Android Studio is when you have the "release" build variant selected. Happened to me - Gradle builds a release version of the app (which is not debuggable) and then Android Studio fails at trying to connect the debugger.


Sync your project with Gradle files and that shall help.


I tested all ways and non of them worked !!!

finally had to change the adb port and it worked. first kill adb server like below:

adb kill-server

then restart it using another port

adb -P 5038 start-server

I did clean build using below command.. Surprisingly worked.

sh gradlew clean build

Hopefully someone get help!


This occasionally happens to me and I have yet to figure out why. None of the already posted solutions have worked for me. The only thing that works for me is to:

  1. Uninstall application from device.
  2. Clean Project. "Build -> Clean Project."
  3. Rebuild and install.

Over the years I have visited this thread many times and there was always a different response that helped me. This time I figure out that it's my USB hub that was preventing debugger to work properly. As strange as it sounds, instead of having a phone connected to my computer via a USB hub, I had to connect it directly to my mac and debugging started to work.


Here's a little oops that may catch some: It's pretty easy to accidentally have a filter typed in for the logcat output window (the text box with the magnifying glass) and forget about it. That which will potentially filter out all output and make it look like nothing is there.


For me, it happened when I used Proguard, so by trying all the solutions I cleaned my project and pressed the debug button on Android Studio and it started debugging


Be sure to enable developer mode and USB debugging on the device or emulator. (Easy to forget when setting up a new one.)


Make sure you have enabled the ADB integration.

In Menu: Tools -> Android -> Enable ADB integration (v1.0)


<application android:debuggable="true">
</application>

That above code is not longer a solution. You need to enable debugging inside your build.gradle file. If you have different buildTypes make sure you set "debuggable true" in one of the build types. Here is a sample code from one of my projects.

buildTypes {
    debug {
        debuggable true
    }

    release {
        debuggable false
    }
}

**I have deleted other lines inside the buildTypes which are not relevant to this question from my gradle file here.

Also Make sure you select the correct build variant in your android studio while doing the debugging.

enter image description here


In my case, i forgot minifyEnabled=true and shrinkResources=true in my debug buildType. I change these values to false, it's worked again!

enter image description here


Another thing to be careful of (I did this so I know, duh). Be sure not to enable Proguard for debug!


I had same problem and I tried almost all kinds of solutions via Google. But I couldn't solve it. Finally, I found the solution. This is Android Studio Bug.

Do not click Run (Alt + F10) — just click Debug (Shift + F9).

Then Android Studio will show you the Warnning Message with ADB, Then Just click "OK".

You can see log in logcat console. And Packages will be shown on DDMS(Devices).


"Attach debugger to Android process" icon shoud be used in case when you set custom "android:process" in your Manifest file.
In my case I should select suitable process and click OK button just after "Wait for debugger" dialog appears.
enter image description here


I was able to fix it by going to Run -> Edit Configurations, selecting my project, selecting the Debugger tab, then changing 'Debug type' from 'Auto' to 'Dual':enter image description here


I solved this issue after doing the following steps:

Go to Tools==>android==>Disable ADB integration and enable it again.

After that, unplug USB from device and plug in again.

Finally press shift + F9


In my case, Had to remove the proguard in debug Build Type by completely clearing the text file proguard-rules.pro and making minifyEnabled false in build.gradle file

  debug {
            debuggable true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

If your Application used to be debuggable, and suddenly it's no more debuggable.Here is my solution

  1. disable and enable USB debug switch in your phone.
  2. Uninstall your application.
  3. click Run in Android Studio.

This solved my problem. Uninstall app from device and run it again via Android studio.


    <application android:debuggable="true">
</application>

This no longer works! No need to use debuggable="true" in manifest.

Instead, you should set the Build Variants to "debug"

Debug Mode

In Android Studio, go to BUILD -> Select Build Variant

Now try debugging. Thanks


What worked for me in Android Studio 3.2.1

Was:

RUN -> Attach debugger to Android Process --> com.my app


You also should have Tools->Android->Enable ADB Integration active.


In my case near any line a red circle appeared with a cross and red line with a message: "No executable code found at line ..." like in Android studio gradle breakpoint No executable code found at line.

A problem appeared after updating of build.gradle. We included Kotlin support, so a number of methods exceeded 64K. Problem lines:

buildTypes {
    debug {
        minifyEnabled true

Change them to:

buildTypes {
    debug {
        minifyEnabled false
        debuggable true

Then sync a gradle with a button "Sync Project with Gradle Files". If after restarting of your application you will get an error: "Error:The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html", then, like in The number of method references in a .dex file cannot exceed 64k API 17 add the following lines to build.gradle:

android {

    defaultConfig {
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
    implementation 'com.android.support:multidex:1.0.2'
}

UPDATE

According to https://developer.android.com/studio/build/multidex.html do the following to enable multidex support below Android 5.0. Else it won't start in these devices.

Open AndroidManifest and find tag <application>. Near android:name= is a reference to an Application class. Open this class. Extend Application class with MultiDexApplication so:

public class MyApplication extends MultiDexApplication { ... }

If no Application class set, write so:

<application
        android:name="android.support.multidex.MultiDexApplication" >
    ...
</application>

Restart the adb server, from android studio: Tools -> "Troubleshhot Device Connection"


Check, if you're app-project is selected in the drop-down menu next to the debug-button. Sometimes Android Studio just resets this selection...

enter image description here


In my case, I was trying to debug from a QA build. Change the build variant to Debug and it should work.

To change the build variant, click the menu on the left bottom named "Build Variants"

enter image description here

In case this menu is not available in your IDE you can do the following.

  1. Double click your shift button and you should see a search window popping.
  2. Type "Build Variants" as shown below

enter image description here 3. Now change your build to debug from QA or Release.


This worked for me in Android Studio 3.6.3

Settings -> Build, Execution, Deployment -> Debugger -> Android Debug Bridge -> Enable 'Use libs backend'

enter image description here


Also make sure you're not using other applications that might be using ADB too, like Eclipse for example.


I also randomly had this problem even after debugging many times in Android Studio. One day the debugger just wouldn't attach. I just had to quit Android Studio and reopen it and the debugger started working again.


This worked for me:

  1. Close Android Studio.
  2. Open the shell, and write:

    adb kill-server

    adb start-server


If you enable

<application android:debuggable="true">
</application>

In the application manifest.xml make sure you disable it when generating the final signed apk since this can serve as a security loop hole for attackers. Only use it if only one of your applications does not show the logs. However before considering that option try this:

Navigate to tools in the android studio

 Tools==>android==>disable adb integration and again enable it

In my case I had the same problem because I try to debug signed apk. In my gradle config I made differents build variants, and try to debug release build with production keystore.jks


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to debugging

How do I enable logging for Spring Security? How to run or debug php on Visual Studio Code (VSCode) How do you debug React Native? How do I debug "Error: spawn ENOENT" on node.js? How can I inspect the file system of a failed `docker build`? Swift: print() vs println() vs NSLog() JavaScript console.log causes error: "Synchronous XMLHttpRequest on the main thread is deprecated..." How to debug Spring Boot application with Eclipse? Unfortunately MyApp has stopped. How can I solve this? 500 internal server error, how to debug

Examples related to adb

ADB server version (36) doesn't match this client (39) {Not using Genymotion} ADB device list is empty "unable to locate adb" using Android Studio Run react-native on android emulator Solving "adb server version doesn't match this client" error Adb install failure: INSTALL_CANCELED_BY_USER Session 'app': Error Installing APK Where is adb.exe in windows 10 located? How to debug in Android Studio using adb over WiFi Set adb vendor keys

Examples related to android-studio

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK