Android studio omits breakpoints - android

When I'm trying to debug application using android studio, I set some breakpoints in the IDE and after starting the debugger I've got an info on every single one breakpoint (in the baloon):
Warning : No executable code found at line ...
It looks like the message appears when the application reaches first BP.
Just to be clear - I have executable code in those lines like String s = "asd";

In my case a Build - Clean Project did help.

set the minifyEnabled to false:
From the project section select the project
Right click on project and click open module settings
select the module you are running and from Build Type set the Minify Enabled to false

Try to insert the next snippet code into the android{} block on the app build.gradle file:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false //<---- THIS FIX THE PROBLEM
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'pro
guard-rules.pro'
}
}

Do you debug on device or on emulator? If device then try to switch back to Dalvik from ART
The first line breakpoint works only

Responding to user3167086's post -
I had the same problem with the breakpoints not working in the middle of a method. One line of code was fine, and the break point icon had a "check mark" in it, but the next point had an "x" in the icon and gave the warring of "no executable code". I checked the Project Structure and the Build Type had already defaulted to "false", but I set it to false again and clicked OK.
For those using Android Studio 1.5 like I am, the complete procedure - using the main menu - is to
select File -> Project Structure.
Then select your "App" module on the left, and then the "Build Types" tab across the top.
Make sure you have "Debug" selected and not "release" on the left (you should see this at the top of the right hand column too) and then set Minify Enabled to FALSE.

Make sure that you use a "Debug" build variant - otherwise breakpoints don't work.

I saw this error message in a pop-up over the dreaded breakpoint with an X in it, in Android Studio's "stable" version 2.1.2 (Gradle: 2.10, Android Plugin: 2.1.2), and the fix was to simply hit the red 'stop' button on the current run session in Android Studio.
I have no idea how the current run session could interfere with setting a break point in source (I have everything under 'Instant Run' unchecked), but this worked for some reason.

For the future:
In my case ALL lines of code were unavailable for debugger. Solution for my problem was disabling jack to avoid creation of intermediate code.
These lines in my gradle.build were to blame:
defaultConfig {
jackOptions {
enabled true
}
}
I turned jack options on several months earlier and then switched back to Java7 forgetting about how my application works. No suprisde Android Studio couldn't find matching code.
I hope it will help.

Related

"No debuggable process" is shown in Android Studio Profiler

When I try to use profiler in Android Studio, I am able to see my connected device but I am getting "No debuggable process" in the Profiler. Can someone please help me why i am getting "No debuggable process".
You can try any/all of the following:
Invalidating cache and restarting your Android Studio: To do this, from the menu bar select File > Invalidate Caches / Restart
Restart your phone
Disable and enable USB debugging
Restart your computer
You can also check if your app is marked as debuggable in build.gradle. To do this, just go to your app-level build.gradle file, and under buildTypes check if the debuggable property is set to false, if yes change it to true. Something like:
buildTypes{
release {
debuggable false
}
debug {
debuggable false
}
}
Alternatively, to do the same you can also do it the old way by adding the following line to your Manifest file under the Application tag:
android:debuggable="true"
This should fix it.

Android Studio cannot find local variable in debugger

When I try to debug my app, I can't see variables values in the debugger.
I have the following error when I try to evaluate an expression for instance (same with variables watchers) :
Cannot find local variable 'data' with type com.myorg.myapp.data.objects.DataToUpdate
The IDE seems to understand the type of my variable but it can't find it.
The variable is used just after so it has not been optimized away.
I belive that the code has been optimized but only part of it.
I built an apk and decompiled it with some decompilers online to see if it was minifyed or something.
Part of my code is not
My class fields are ok, I can see their values in the debugger and their name is the same as in my code
However, other parts of my code seem to be optimized (variables names are not the same)
E.g. : my variable "data" of type DataToUpdate becomes "DataToUpdate r118" in the decompiled code
I had nothing put in the debug buildType of my build.gradle. I added the following lines according to what I saw on the web to try to make it work :
buildTypes {
debug {
debuggable true
testCoverageEnabled = false
minifyEnabled false
useProguard false
}
}
I am using Android Studio 4.0 Beta 4 but it also didn't work reliably in Android Studio 3.6.
I ended up using the logcat to understand and then correct the bugs in my code.
The debugger worked in other methods so it may be usefull to try to reproduce the problem in other methods, to debug it there.
A debugger working as expected would be better, but I couldn't make it work in this particular method.

How to programmatically tell if my app is being debugged?

I'm looking for a way to tell if my app is running under the debugger or running "normally", under Android Studio..
These two cases are
1. Run the app by clicking the "Run app" button (green arrow)
2. Run the app by clicking the "Debug app" button (gear icon)
I would like to output more verbose diagnostics (using Log.*) while debugging.
I tried checking BuildConfig.DEBUG but that is TRUE in either case. I suspect this is because Android Studio signs the app with the Debug Certificate in both cases.
Does anyone know how to distinguish these two cases at runtime?
typically one would check for BuildConfig.DEBUG (or a boolean variable holding it) and then log:
if(BuildConfig.DEBUG) {Log.d("SomeActivity", "debug message");}
see the documentation... most relevant for debugging is build-config debuggable true/false.
the run button does not start the debugger; no matter the build-config (it just skips all breakpoints).
in multi-module projects, one should check with:
(getContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0
to tell them apart, two build types need to be configured:
android {
...
buildTypes {
debug {
...
renderscriptDebuggable true
jniDebuggable true
debuggable true
}
release {
...
renderscriptDebuggable false
jniDebuggable false
debuggable false
}
}
}
and to precisely answer the question, there even is one method called isDebuggerConnected(), which would always return false when hitting the run button (no matter the build-config).
"Run app"
This will install the application into your device/emulator
"Debug app"
This will enable you to debug function by placing the break points into your code.
which means you will be able to stop execution of code at that point and debug it line by line. To know more about debugging in android see this
Both the application are debug applications.
To know more about build type please read this

java- Android Studio [ClassNotFoundException]

I got problem when change name packages in android studio,
first i use some open source project, then when i want to change the previous packages some of function cant be used, the error message is "ClassNotFoundException:yuku.kpri.model.Song" even thoughni already change packages "yuku" to "buna" and all packages that related to "yuku" change to "buna" and also packages "yuku.kpri.model.Song" changes to "buna.kpri.model.Song" but the code still run to yuku.kpri.model.Song,
I already try many solution like
Close/Unselect Compact Empty Middle Packages ,Then right click your package and rename it. Here
Clean Project
Rebuild Project
change the applicationId Here
Error Message when try to use the function
Here
Help me to solve this problem, what i miss and my mistake...
im looking for your answer
One thing you could try is selecting File --> Invalidate Caches/Restart, sometimes it works magic.
This could be a Proguard issue.
Try to set "minifyEnabled false" for both Release & Debug build types in your projects build.gradle file :
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled false
}
}
If this works, you should exclude the class in the proguard-ruls.pro file.

Unable to open debugger port : java.net.SocketException “Socket closed”

I'm using Android Studio, with multiple flavors using Gradle, each with a Debug and Release type, organized as described here, on the bottom half.When I try to start the debugger, I get this error:
Error running androidRecover [installAppDebug]: Unable to open debugger port : java.net.SocketException "Socket closed
I'm also unable to attach the debugger to my device once it's running (it only displays the name of my phone, not the app).
All 3 flavors install on my phone just fine. I just can't get it to let me debug them. I also tested attaching the debugger on a Nexus tablet, and I got the same result.
It's not Gradle specifically as a whole because I can run other Gradle-based apps and attach the debugger just fine so I wonder if it's something with how I've setup my Gradle project and settings.
Here's my build.gradle:
apply plugin: 'android'
apply from: 'signing.gradle'
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile
('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
flav1 {
packageName "com.ex.flav1"
versionCode 32
versionName "1.0.5"
signingConfig signingConfigs.flav1
}
flav2 {
packageName "com.ex.flav2"
versionCode 33
versionName "1.0.6"
signingConfig signingConfigs.flav2
}
flav3 {
packageName "com.ex.flav3"
versionCode 27
versionName "1.0.0"
signingConfig signingConfigs.flav3
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/httpmime-4.2.5.jar')
}
I really have no idea what else to try. Android Studio is completely up-to-date. I've restarted Android Studio, my phone, and my computer.
Also, last week I was having this problem, but it was a specific socket that was blocked, from trying to run the emulator and my phone at the same time. I also noticed I had multiple Gradle processes running, because it wasn't killing them on its own, which I often had to kill Android Studio to kill them. Once that was fixed, it was working off and on.
Let me know if you need any other info.
Thanks,
Devin
Edit I finally know why #hasanaydogar's answer works and why it probably would have solved my problem if we had known it then. See my 2nd comment on it to know why, but in short, you have to select in that dropdown the name that matches your app's root directory.
Just Click the button (left side the RUN button).
Select Android. Then Run.
It will connect to your device.
And dont forget to change build variant
I finally understand why I was getting that error so I'm going to explain how I Debug now. Note that I use Gradle (build multiple apk's using the same code), which might influence some how you use the third part of this answer.
For these to work, in the dropdown next to the debug (icon in #1) and run buttons in the top toolbar, you have to have the one selected with the following icon next to it because that's the name of the root directory of your app where all your code lives:
To start debugging from the beginning, I run the app in Debug mode from the start, using this button in your toolbar:
To attach the debugger to the app when it's already running as #scottyab mentioned, I click the Attach Debugger button in your toolbar:
To run the release version of my app in debug mode, I've started changing my strings in the Debug version of strings.xml in the file path myApp/src/appNameDebug(verses appNameRelease)/res/values/strings.xml, more easily seen here, on the bottom half. When I say change, I really mean that I have two versions of all the strings (3 in my case) necessary to change from using the debug server to using the release server. It might not be completely kosher, but it takes about 5 seconds to go the file, and hold down Cmd+/ and uncomment and comment all of the appropriate lines.
My Release version is just there for when I'm ready to build an apk for release.
Doing things in this way has eliminated that error popping up anymore. I think the Release version is just not made for debugging, and I haven't found an easy way to turn the debug flags on when in Release mode.
I managed to get this working by attaching the debugger after a build see Unable to open debugger port : java.net.SocketException "Socket closed"
I managed to get rid of this problem by killing & restart the adb process,hope this would help :]
I have solved this question with reference to the following SO Answer
The "Select Run/Debug Configuration" button in android studio 2.3.2
Change the Debug type to Native

Categories

Resources