Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run block of code only in release mode in android

Tags:

android

I have two builds variant one is in debugging and other is release. I have to run some block of code in release mode. For example, I have to use Firebase only in the release build,Is there any way to do that?

like image 834
Nitt Avatar asked Nov 26 '16 10:11

Nitt


People also ask

Can we debug in release mode Android?

It means you have to give sign build in debug version also in build gradle. So It will have the same sign as release build and you can debug when it runs.

Can I debug in release mode?

You can now debug your release build application. To find a problem, step through the code (or use Just-In-Time debugging) until you find where the failure occurs, and then determine the incorrect parameters or code.

How do I run Android in debug mode?

Press Ctrl + Alt + F5 (or Shift + F9 ) to launch the app in debug mode. Choose Run -> Attach to process and select the signature of an app to enable the debug mode, which is already installed via adb.


2 Answers

For Check the release mode use

 if( BuildConfig.BUILD_TYPE.equalsIgnoreCase("release")) {

   }

debug mode check

 if( BuildConfig.BUILD_TYPE.equalsIgnoreCase("debug")) {

   }

or you can use this code

  if( BuildConfig.DEBUG ){
    }
like image 186
Nithinlal Avatar answered Sep 30 '22 14:09

Nithinlal


use BuildConfig.DEBUG to check is in debug mode

like image 25
ramin eftekhari Avatar answered Sep 30 '22 14:09

ramin eftekhari