Debugging The Release Build Type Without Generating a Signed APK
After a lot of research I decided to go ahead with my debugRelease
idea and it seems to be working well.
I create a new directory under app/src
called debugRelease/java
. In there I put any code that I wanted to be different when I generated a signed apk or release version.
Doing so enables me to test the code works and be able to debug it. Granted this isn't done very often and it's only crash reporting and logging differences but, on the off chance I need to fix a bug or something, I can.
In my build.gradle
file, I have the following setup.
buildTypes {
release {
}
debug {
}
debugRelease {
signingConfig signingConfigs.debug
}
}
sourceSets {
debugRelease {
res.srcDirs = ['src/debug/res'] // this uses the debug's res directory which contains a "debug" icon
}
release {
java.srcDirs = ['src/debugRelease/java'] // this avoids copying across code from the debugRelease java directory
}
}
So now when I want to test the release code, I just change my build variant to debugRelease
.
You can build a release variant of your app (to use your production environment for example), with the following properties:
- Full debugging enabled
- Disabled ProGuard obfuscation and code shrinking
- Disabled APK signing with the release certificate
Make these temporary changes to your app/build.gradle:
/* ADD THIS BLOCK, IF NOT ALREADY THERE */
lintOptions {
// When you make a Release Build, the Android Lint tool will run to check many things.
// It is set to abort the build on a single Lint error/warning. Disable this.
abortOnError false
}
buildTypes {
release {
//minifyEnabled true // <-- COMMENT OUT
//proguardFiles ... // <-- COMMENT OUT
//shrinkResources true // <-- COMMENT OUT
signingConfig signingConfigs.debug // <-- ADD THIS TO SIGN WITH YOUR DEBUG CERTIFICATE
debuggable true // <-- ADD THIS
minifyEnabled false // <-- ADD THIS
}
}
Then do Android Studio ➔ View ➔ Tool Windows ➔ Build Variants ➔ Select appRelease
or whatever yours is called, then press the Run button to build and install it.
More info/related articles:
- How to debug apk signed for release?
- How to debug the Android App in release mode using Android studio
- https://mobikul.com/release-variant-of-app-enable-logcat-running-release-build-application/
- Unable to switch to debug build variant in Android Studio