• 7
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

For some reason I have to run my Android App in release mode.I have to run through the code when running the app just like we use in debug mode. My break points are not hitting when I run in release mode, I have added android:debuggable="true" in manifest. Still the breakpoint is not hitting. Any help.

Thanks in Advance

In your gradle file, you must add debuggable ability in your release flavor.

buildTypes {
    release {
        debuggable true
        minifyEnabled false
        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
    debug {
        debuggable true
        minifyEnabled false
        applicationIdSuffix '.debug'
    } 
}

signingConfig is release configuration it must be added in gradle file in android{} block, something like this:

signingConfigs {
    release {
        keyAlias 'YourAppKey'
        keyPassword 'somePassword'
        storeFile file('appkeyfile.jks')
        storePassword 'somePassword'
    }
} 
  • 39
Reply Report
      • 2
    • I have added this in my build gradle. But I don't have a signingConfigs.release file. my signingConfig is signingConfigs.config. How can I generate one for release ??
    • I have added this all and Still my breakpoint is not hitting. Is there anything else that remove the breakpoint in the code??
      • 2
    • You can add release { signingConfig signingConfigs.debug } to sign the release build with your debug certificate.

In my case, I have created the debug configuration same as previous release build and started debugging. It means you have to give sign build in debug version also in build gradle.

signingConfigs {
    config {
        keyAlias 'abc'
        keyPassword 'xyz'
        storeFile file('<<KEYSTORE-PATH>>.keystore')
        storePassword 'password'
    }
}
buildTypes {
  debug {
      debuggable true
      signingConfig signingConfigs.config
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

So It will have the same sign as release build and you can debug when it runs.

  • 10
Reply Report

There's no "release mode". What you refer to is the build type which means steps taken during building (like minifying etc). Setting android:debuggable="true" will not automagically help, because when you "Run" the app instead of "Debug" you do not connect debugger to it so it will not stop for that particular reason.

So you can set up your debug build to be produced the same way release is, but is quite unclear what is the reasoning behind your need and I got a feeling you are trying to go the wrong way (i.e. debug is usually not using ProGuard, while release build is and ProGuard changes the resulting binary so your breakpoints from source will not really work anyway).

  • 1
Reply Report
    • I have a need to debug an issue that only affects release builds, which suggests that it is a bug created by shrinked/obfuscated/optimized code. The issue is not observed on debug variants

I think Marcin's argument above makes sense (much as there are situations that require debugging release builds), so here is a slight variation of the accepted answers that worked for me:

android {
    ...
    buildTypes {
        release {
            shrinkResources false # this was key
            minifyEnabled false # seems that it can't be set to true if shrinkResources is false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }
}

Adapted from the official docs

NOTE:

When I set minifyEnabled true, the following crash occurred on app launch:

java.lang.RuntimeException: Unable to instantiate application co.mycompany.app.MyApp: java.lang.ClassNotFoundException: Didn't find class "co.mycompany.app.MyApp" on path: DexPathList...
  • 0
Reply Report