Android Studio 2.1 debugger does not show local variables - android

I am trying to debug over network in Android Studio. I connected via port 5555 and generally it is possible step through break points. But it often takes minutes just to execute one line of code and the other thing is that I don't see any variables which are no members. All I see is the this object, but no variables from within methods. How can I enable it?
As you can see I am within the method and at least the activity object is initialized, but it is not visible in the variables monitor.
UPDATE:
The problem remains when using USB debugging. No local variables are visible, not even when trying to evaluate expressions while debugging:
Android Studio 2.1, Gradle 2.1.0, Java 1.8

Had the same problem.
There is a bug in Android Studio, see https://code.google.com/p/android/issues/detail?id=93730
They recommend removing in build.gradle (app), this fixed the issue for me.
android {
buildTypes {
debug {
...
testCoverageEnabled true
}
}
}

After a while of figuring out this same issue, I realized I was running a release build rather than a debug build.
The build variants window may not be open in Android Studio by default. Go to Tool Windows -> Build Variants. In the Build Variants window, select the appropriate build.
In your app.gradle file, make sure debuggable is set to true in the build variant you would like to debug:
android {
// ...
buildTypes {
release {
// ...
}
debug {
debuggable true
}
}
// ...
}
If you would like to debug your release build, go ahead and add debuggable true to your release build.
Hope this helps!

I tried setting testCoverageEnabled to false but that did not work for me. In my case, I had ProGuard enabled for my debug flavor and disabling it (i.e. setting minifiyEnabled to false) was the only thing that allowed me to be able to see my local variables while debugging again.

In my case, it was because I had forgotten that my build variant was set to release. Toggling the variant back to debug and re-running correctly showed the local variables.

For me I had to set testCoverageEnabled to false like so:
android {
buildTypes {
debug {
...
testCoverageEnabled false
}
}
}
When I had this set to true, I was not getting local variables

While this is not a permanent solution to this problem, my most consistent fix (after trying the other answers here to no avail) has simply been restarting my computer.

I tried some kind of hit n trial and made it work with the settings as seen in the attachment. FYI, using latest version of Android Studio 3.3.1 and gradle version 4.6.

I had same trouble. I completely reinstalled my IDE and the trouble has been disappeared. I hope my approach will help you.

Java 1.8 does not support accessing variable values.
Update Gradle to version 2.2.0-beta3:
In your gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
In your project build.gradle file
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-beta3'
}

Related

Android Kotlin: Local Variables unavailable during debugging

Starting today I am unable to debug locally scoped variables in Kotlin using Android Studio 4.0.1 (Build number AI-193.6911.18.40.6626763). Yesterday I did not have this issue.
I'm using android gradle 4.0.1 and build gradle of 6.1.1, after having tried rolling back I've reset to those.
Example code that I cannot debug:
private fun collapse(){
val start = endIndicies[2]
val end = endIndicies[3]
...
}
My debugger has no problem with resolving object scoped members, however locally scoped variables do not resolve when stepping through the code:
I'm running a debuggable build.
I have invalidated caches and restarted.
I have cleaned and rebuilt the project.
I have tried rolling back to previous gradle versions.
I have tried adding -dontobfuscate to my proguard file.
I've deleted my build files from the app folders, then rebuilt.
My debug config in the app/build.gradle file looks like this:
debug {
debuggable true
minifyEnabled false
shrinkResources false
}
When I attempt to debug code in a library that is pulled in via gradle I have no issues debugging locally scoped variables.
app/build.gradle
dependencies{
implementation project(':com.example.core')
...
}
So I'm fairly certain it's a configuration issue with the app module, and I suspect it's some rogue R8 obfuscation issue, though I'm not sure what.

Libgdx - Gradle Android debuggable

I would like to make my app debuggable.
When I deploy to my nexus 5x I get this error:
Error running AndroidLauncher: Cannot debug application from module android on device lge-nexus_5x-(code here). This application does not have the debuggable attribute enabled in its manifest. If you have manually set it in the manifest, then remove it and let the IDE automatically assign it. If you are using Gradle, make sure that your current variant is debuggable.
If I add the debuggable="true" attribute to the android tag in my manifest it works.
But I'm forgetful, so I'd rather do it the proper way with gradle.
I've tried to add a lot of the things I've found on the internet to both my Android module build.gradle, and my project's root level build.gradle.
All to no avail.
What should work?
Thanks,
Chase
On an tangent, I also tried running my HTML module using the instructions from their site, and it says it's failing because I'm using java 1.7 features but the gradle source is 1.6. I've also tried googling that to no avail. I was adding some lines like this:
sourceCompatibility 1.7
targetCompatibility 1.7
You can use build types (Build Variants) in your android gradle file:
project/android/build.gradle
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
}
release {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
minifyEnabled true
pseudoLocalesEnabled false
debuggable false
signingConfig signingConfigs.AndroidKey
}
}
* There is some proguard stuff and signing config you might not need. Just remove from the release build variant.
You don't need any other configuration in other files. You can see the full source I used in my project here.
If you are using Android Studio you can change between your build variants here:
When you run the project if release is selected it will install the non debugable apk in your device. Otherwise, if debug is selected it will install the debugable apk. Both can be installed at the same time. It will show the app twice in your device.
The problem is that it should be debugable by default. You could remove the debuggable true line and the debug build variant should still be debugable.
If it does not work paste your manifest and your build.gradle files here so we can see what is going on.
You can look all theses files in my project. It is also a libGDX project, but it don't have the HTML module.
The Build Variant docs might be helpful.

Why Proguard runs despite having minifyEnabled in gradle config?

According to documentation setting minifyEnabled to false must disable ProGuard run
integration {
minifyEnabled false
versionNameSuffix "-int"}
But the ProGuard is still started by Gradle! Any ideas why?
You will need to change the Build Variant to use one of the integration build variants (from the bottom left in android studio), if you want to use the configuration for integration buildType.
From what you describe you appear to be using a different buildType. By default it is debug. Make sure an integration Build Variant is selected and you should be good.
As it often happens, I found and answer after posting my question.
"This is not a bug, this is a feature":
https://groups.google.com/forum/m/#!topic/adt-dev/iS_lyRH8hL8
This is not really a problem, but certainly annoying.
The output you are seeing is related to the way the Android gradle plugin determines the set of classes that must be in the main dex file when multidex is enabled. For this purpose it uses ProGuard internally, but it is unrelated to your configuration.
In order to disable the logging output of this task, you can add the following to your build.gradle file:
tasks.whenTaskAdded { task ->
if (task.name.startsWith("transformClassesWithMultidexlistFor")) {
task.logging.level = LogLevel.ERROR
}
}

BuildConfig.DEBUG always return false

Why does BuildConfig.DEBUG return false, when I run the application?
I use it to control the log like the following:
public static void d(String LOG_TAG, String msg){
if(BuildConfig.DEBUG){
Log.d(LOG_TAG,msg);
}
}
Check imports in the class, make sure you are using correct BuildConfig path. You may use BuildConfig not from your app, but from some library.
In your Android Studio build variant are you on debug variant?
That is applied when you use flavors, either for debug or release.
in the debug mode, BuildConfig.BUILD is true, and in the release mode, it is false.
Ensure the auto import statement of build config on the top of your class belongs to your project.
com.your.package.name.BuildConfig
the BuildConfig import might belong to a released library there DEBUG is false.
If that code is in a library, then it'll always be false, thanks to a 3-year-old bug in gradle.
Do not import BuildConfig. This is an auto-generated class and importing it is unnecessary, despite what Android Studio may tell you.
If Android Studio is prompting you to import BuildConfig it may be because you need to do an initial Gradle build to create the auto-generated class which ends up being created at com.yourdomain.yourapp.BuildConfig. This can happen when you upgrade Android Studio and Gradle, or when you run Build -> Clean project.
If you import another package's BuildConfig, then of course it'll always be false because they are only releasing their release flavours and not their debug flavours.
Regarding the other answers recommending modifying your build.gradle, I found that specifying buildType conflicted with the default behaviour of Android Studio and its generation of BuildConfig, stating I had a duplicate entry.
So essentially:
Do not import any package's BuildConfig (so let it stay red)
Do not add buildType to your build.gradle (this may conflict with the default build behaviour of auto-generating the class)
Ignore the lint error
Run build
The error should go away.
I experience this when I upgrade Android Studio and Gradle and when I clean the project.
Ignore import prompts
Do not import another package's BuildConfig—it'll always be false because they are not releasing their debug versions.
Importing will cause the error you're experiencing
In my project, if I import one of the suggested libraries, it'll show the error you're getting, because no one releases a debug build so of course it'll always be false if you're pointing to someone else's.
Ignore the intellisense and run the project
Just run a build. The class will be auto-generated and the warning will go away.
I specified debuggable true in build.config, but this is always false
After this change (simply remove it), all was working properly :
There is a workaround for the problem:
App
dependencies {
releaseCompile project(path: ':library', configuration: 'release')
debugCompile project(path: ':library', configuration: 'debug')
}
Library
android {
publishNonDefault true
}
Perhaps not ideal, but I ended up creating my own
buildTypes {
debug {
buildConfigField "boolean", "IS_DEBUG", "true" // Had issues with BuildConfig.DEBUG, created IS_DEBUG to ensure functionality behaved as expected.
}
release {
signingConfig signingConfigs.release
buildConfigField "boolean", "IS_DEBUG", "false"
}
}
And then address it like BuildConfig.IS_DEBUG programatically.
Maybe you are importing the wrong package, check that. (some Android libraries also have the BuildConfig class)

Is it possible to test against the release version of your app with Android Gradle plugin?

When I use the 'gradlew connectedCheck' command it always build the debug version and test against the debug version of my app. Is it also possible to test against the release version of my app?
I want to enable proguard and want to make sure that it doesn't filter anything out that is needed during runtime.
You can only test against a single build type right now (though that may change).
To set the build type to test against:
android {
testBuildType "release"
}
You could set this dynamically through a env var to not have to edit build.gradle all the time.

Categories

Resources