How to debug the Android App in release mode using Android studio

前端 未结 5 1844
不知归路
不知归路 2020-12-14 14:48

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 hitt

相关标签:
5条回答
  • 2020-12-14 15:10
     buildTypes {
        release {
        debuggable true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
    }
    

    happy coding.Mark this answer up..if it helps.. :)

    0 讨论(0)
  • 2020-12-14 15:15

    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 讨论(0)
  • 2020-12-14 15:21

    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).

    0 讨论(0)
  • 2020-12-14 15:28

    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'
        }
    } 
    
    0 讨论(0)
  • 2020-12-14 15:32

    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.

    0 讨论(0)
提交回复
热议问题