Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio's debugger not stopping at breakpoints within library modules

At the moment I'm developing an Android app that is based on third party code. I started to set breakpoints for understanding the code and soon ran into a problem. Suddenly I couldn't get Android Studio to stop at breakpoints anymore.

I tried to set the breakpoints within onCreate methods, within buttons' OnClickListeners - nothing worked. Now I found out that the only place it works is inside the app module. As the project just has one single activity class in the app module and everything else is provided within library modules in fact I can't debug at all.

I assume there's something wrong in the AndroidManifest.xml or more likely in the build.gradle file. As I just switched from Eclipse to Android Studio, all of this gradle stuff is pretty new to me.

If I hover over a library breakpoint while the app is running, it tells me that "no executable code [is] found at line ...". I assume this is the cause of my problem, but I have no idea about how to fix it.

Are there any "usual suspects" among the entries in build.gradle that could cause my problem?

I already did clean my project and invalidated the cache without success. I even tried the suggestion to add <activity> entries inside the library module for the fragments inside.

Edit: I'm using the most current version of Android Studio (version 1.1.0 from February 18) which should have the similar bug fixed that existed some time ago.

The contents of build.gradle in the app module:

apply plugin: 'com.android.application'  android {     compileSdkVersion 19     buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION      defaultConfig {         minSdkVersion Integer.parseInt(project.MIN_SDK)         targetSdkVersion  Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)     }      signingConfigs {         release {             keyAlias 'xxx'             keyPassword 'xxx'             storeFile file('xxx')             storePassword 'xxx'         }     }      buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'             signingConfig signingConfigs.release             debuggable false             jniDebuggable false             zipAlignEnabled true         }         debug {             minifyEnabled false             debuggable true         }     }      packagingOptions {         exclude 'META-INF/DEPENDENCIES'         exclude 'META-INF/NOTICE'         exclude 'META-INF/LICENSE'         exclude 'META-INF/LICENSE.txt'         exclude 'META-INF/NOTICE.txt'     }     productFlavors {     } }  dependencies {     compile fileTree(dir: 'libs', include: ['*.jar'])     compile project(':firebase_plugin') } 

And the build.gradle of library module:

apply plugin: 'com.android.library' android {      compileSdkVersion 19     buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION     defaultConfig {         minSdkVersion Integer.parseInt(project.MIN_SDK)         targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)     }      buildTypes {         release {             minifyEnabled true             zipAlignEnabled true             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'         }         debug {             minifyEnabled false             debuggable true         }     }      productFlavors {     }  }  dependencies {     // Facebook SDK     compile project(':facebook')      // Used for StringUtils     compile files('libs/commons-lang3-3.3.2.jar')     // Bug tracking     compile files('libs/bugsense-3.6.1.jar')     compile fileTree(include: ['*.jar'], dir: 'libs')     //Google Play Services - For Google Maps     compile('com.google.android.gms:play-services:5.0.89') {         exclude group: 'com.google.android', module: 'support-v4'     }     // Support Library.     compile 'com.android.support:support-v13:18.0.+'      compile('com.android.support:appcompat-v7:19.1.0') {         exclude group: 'com.google.android', module: 'support-v4'     }     // Volley - Networking library from google.     compile('com.mcxiaoke.volley:library:1.0.0') {         exclude group: 'com.google.android', module: 'support-v4'     }     // Has is own support library in it so need to exclude it so no TOP_LEVEL_EXCEPTION will occur.     compile('de.greenrobot:greendao:1.3.0') {         exclude group: 'com.google.android', module: 'support-v4'     }     // Firebase     compile('com.firebase:firebase-simple-login:1.4.2') {         exclude group: 'com.android.support', module: 'support-v4'     }     // Super Toast     compile('com.github.johnpersano:supertoasts:1.3.4@aar') {         exclude group: 'com.android.support', module: 'support-v4'     }     // Croping images     compile('com.soundcloud.android:android-crop:0.9.10@aar') {         exclude group: 'com.android.support', module: 'support-v4'     }     compile('com.github.chrisbanes.actionbarpulltorefresh:library:0.9.9') {         exclude group: 'com.android.support', module: 'support-v4'     } }       packagingOptions {         exclude 'META-INF/DEPENDENCIES'         exclude 'META-INF/NOTICE'         exclude 'META-INF/LICENSE'         exclude 'META-INF/LICENSE.txt'         exclude 'META-INF/NOTICE.txt'     }     productFlavors {     } }  dependencies {     compile fileTree(dir: 'libs', include: ['*.jar'])     compile project(':firebase_plugin') } 

enter image description here

like image 907
olik79 Avatar asked Mar 03 '15 15:03

olik79


People also ask

Why does Visual Studio not stop at breakpoint?

This problem occurs because ASP.NET debugging isn't enabled on the application.

How do I terminate debugging?

Click Stop Debugging on the Debug menu to stop the target's execution and end the target process and all its threads. This action enables you to start to debug a different target application. )

How do you stop breakpoints?

To disable a single breakpoint You can disable a single breakpoint in one of the following ways: In the Query Editor window, right-click the breakpoint, and then click Disable Breakpoint. In the Breakpoints window, clear the check box to the left of the breakpoint.

Do breakpoints stop all threads?

By default only the thread that hits the breakpoint stops. However, you can modify the behavior by changing the breakpopint properties. Save this answer.


2 Answers

As stated in the comments of this issue, setting minifyEnabled false in the debug build is the best practice. By setting this variable in the app module you are disabling the entire proguard build process. It is useful when optimizing the release build, but gives some problems if you are testing and developing.

like image 107
droidpl Avatar answered Sep 28 '22 06:09

droidpl


I kind of solved it, although I don't fully understand it yet. The problem was that ProGuard still was active like @Feantury suggested. I don't know why that was the case as I had specified minifyEnabled false in every build.gradle position I could imagine, but it seems it didn't have any effect.

As I had a crash just a few minutes ago, I saw lines in the stacktrace that looked like so:

java.lang.NullPointerException         at com.example.MyClass(Unknown Source)         ... 

That made ProGuard the number one suspect for me. After some searching around, I found another SO question that deals with the Unknown Source problem. I tried the suggested solution for debugging with ProGuard enabled and voilà it worked!

Simply add the following lines to proguard-rules.txt:

-renamesourcefileattribute SourceFile     -keepattributes SourceFile,LineNumberTable 
like image 20
olik79 Avatar answered Sep 28 '22 05:09

olik79