Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging The Release Build Type Without Generating a Signed APK

I have a project setup with two build types: debug and release.

In my app module I have three different directories: debug, release and main.

What I want to do is test the code in the release directory but the only way I can seem to do that is to generate a signed apk and load it onto an emulator that way. This means I can't debug it correctly.

When I change my app module's build variant to release I get the following error in the "Edit Configuration" popup.

Error: The apk for your currently selected variant (app-release-unsigned.apk_ is not signed. Please specify a signing configuration for this variant (release).

What I was hoping to do was extend the release build variant with one called debugRelease in the build.gradle file of the app module which would then inherit the code in the release directory but I would be able to run it from within the IDE.

I may be looking at this the wrong way and I would be glad to hear any other techniques.

Can I do what I'm trying to do? If not what is the best solution for this?

like image 542
StuStirling Avatar asked Feb 25 '16 14:02

StuStirling


1 Answers

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
like image 72
Mr-IDE Avatar answered Sep 20 '22 05:09

Mr-IDE