Search code examples
debuggingandroid-studioproguarddex-limit

Run Debbuger in Android Studio with Proguard On


I want to run the debugger in Android but my issue is in debug build I have proguard on. The reason for this is the stupid 65K method limit. I turned on proguard to help with reducing the methods. This gets me back to 43K methods but now in the IDE I cannot debug stepping through code as all the breakpoints in the IDE turn into red X's with error saying unreachable code. If I close the debugger the breakpoint turns back to normal. Is there something I need to do in the build gradle proguard to get this to work or am I just hosed?

buildTypes {
    debug {
        debuggable true
        minifyEnabled  true
        shrinkResources false
        zipAlignEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        signingConfig signingConfigs.debug
    }
    release {
        minifyEnabled  true
        shrinkResources true
        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-samsung.txt'
    }
}

Solution

  • Your ProGuard config probably misses some clauses.

    I guess you need this:

    -keepattributes SourceFile,LineNumberTable
    

    It will keep (as the name suggests) name of the source files and line number table. Actually, this clause should be used also for release because you can't unambiguously deobfuscate stacktraces without it.

    And for debugging it's good to have this extra clause:

    -keepattributes LocalVariableTable,LocalVariableTypeTable
    

    That will keep local variable names.

    Alternatively, you can consider using these clauses (instead or besides the previous clauses) for debug:

    -dontoptimize
    -dontobfuscate