4

I have a problem with the Android Studio debugger: every breakpoint I set inside a static method is completely ignored. The ones set in non-static methods, on the other hand, work perfectly.

In fact, even if I break just before calling a static method and then manually "step into" it doesn't work. When I step into, it takes me past all the code in my static method to the first piece of code inside a non-static one.

How can I solve this? It makes finding bugs extremely difficult, since I have several helper classees with static methods in my project.

Additional information

Android studio version: 1.2.1.1
Testing on Galaxy s5 - Android Lollipop
Already tried invalidating cache / restarting / cleaning and rebuilding project
No overloaded methods
Didn't touch proguard rules
Minification is not enabled
The code is actually being executed (tested with logcat messages)

Example code:

    private void LoadAvailableExperiments(){ //non static methods, breakpoints work fine here
        try {
            List<ExperimentStoreEntry> storedExperiments = PackageHelpers.GetStoredExperiments(true); //call to static method
        } catch (IOException e) {
            e.printStackTrace();
        }
//rest of the method
}

Then, inside PackageHelpers class:

public static List<ExperimentStoreEntry> GetStoredExperiments(boolean cleanInvalidEntries){ //static method. Breakpoints don't work here
        List<ExperimentStoreEntry> entries = new LinkedList<>(); //breakpoint here is never hit
        File dir = new File(IOHelpers.getExperimentsStoragePath()); //nor here
        if(dir.exists()) { //nor here... etc...
            for (File subdir : dir.listFiles()) {
                //rest of the code I won't bore you with...
        }
        return entries;
    }

EDIT: please, if you -1 the question, at least say why in the comments so I can improve it. I don't know what else to add frankly :/

Master_T
  • 7,232
  • 11
  • 72
  • 144
  • 0. methods with same names but different parameters? 1. android studio version, 2. did proguard "touch" your code? 3. etc ... magic orb is not one of the programmer's tools ... with such little information the only answer is: **It is working for me.** – Selvin May 27 '15 at 08:39
  • @Selvin: edited with more info and code sample – Master_T May 27 '15 at 08:49
  • If you add the breakpoint in Android Studio when the device is connected to the debugger, does the breakpoint turn into a tick or a cross? – FunkTheMonk May 27 '15 at 09:39
  • @FunkTheMonk : no matter if connected or not, breakpoints set inside static methods don't have any symbol, just the red dot. Breakpoints set in non-static methods have a tick. – Master_T May 27 '15 at 09:44
  • 1
    Can you test on another device? might be related to: http://stackoverflow.com/questions/27940583/galaxy-s5-lollipop-not-all-breakpoints-stop-execution-under-android-studio-deb – FunkTheMonk May 27 '15 at 10:09
  • @FunkTheMonk: as a matter of fact, I am actually using a GalaxyS5 with Lollipop, so that may very well be the case. Will test on the emulator now. EDIT: yes, that was the problem!! Thanks you! (reformulate your comment as an answer if you want me to accept it) – Master_T May 27 '15 at 10:12
  • try minifyEnabled false in your debug section of buildTypes in the app gradle file. – Doug Voss Mar 14 '17 at 19:10

1 Answers1

1

As pointed out by FunkTheMonk, this was a problem with the first Lollipop release on the GalaxyS5. Updating the device to the latest firmware solved the issue.

See here for more details: Galaxy S5 Lollipop - not all breakpoints stop execution under Android Studio debugger

Community
  • 1
  • 1
Master_T
  • 7,232
  • 11
  • 72
  • 144
  • 1
    I have the same problem but on Oreo 8.2. It's not a correct answer – IC_ Jan 31 '19 at 23:42
  • I have the same problem in Oreo 8.1. Also, if I add the break point before the static method is called and try to step into the static method the debugger just continues running the code at that point without stepping any more. Also, log messages that I set inside the static method are not printed to the console. I don't think the static method is even being executed! Very strange. – authentictech Jul 01 '19 at 13:40
  • I could only fix my problem by restarting the device I was running the code on. The static method is now running/debugging properly. – authentictech Jul 01 '19 at 19:10