Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Stetho only in the debug build variant

I know that I can use debugCompile to only pull in a dependency for the debug build. Is there a good, streamlined way to do the code initialization that is required as well? Without the dependencies the other variants will fail to compile.

like image 905
theblang Avatar asked May 11 '15 15:05

theblang


People also ask

How to add new build variant in Android studio?

You can change the build variant to whichever one you want to build and run—just go to Build > Select Build Variant and select one from the drop-down menu. To start customizing each build variant with its own features and resources, however, you'll need to know how to create and manage source sets.

How to select build variant in Android studio?

To change the build variant Android Studio uses, select Build > Select Build Variant in the menu bar. For projects without native/C++ code, the Build Variants panel has two columns: Module and Active Build Variant.

What is the build type in Gradle?

Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle. There are two build types defined by default, debug and release , and you can customize them and create additional build types.

What does build type user mean?

Build Type refers to build and packaging settings like signing configuration for a project. For example, debug and release build types. The debug will use android debug certificate for packaging the APK file. While, release build type will use user-defined release certificate for signing and packaging the APK.


1 Answers

Check the @Tanis answer.

Also you can use something like this:

Add the library only on debug version.

dependencies {    debugCompile 'com.facebook.stetho:stetho:1.1.1        } 

In your Application you can do :

public class ExampleApplication extends Application {    @Override public void onCreate() {     super.onCreate();     StethoUtils.install(this);   } } 

Then you can create different StethoUtils class in the debug/release version.

In src/debug/java/

public class StethoUtils{     public static void install(Application application){        Stetho.initialize(           Stetho.newInitializerBuilder(application)             .enableDumpapp(Stetho.defaultDumperPluginsProvider(application))             .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(application))             .build());     } } 

In src/release/java/

public class StethoUtils{     public static void install(Application application){       // do nothing    } } 
like image 197
Gabriele Mariotti Avatar answered Sep 30 '22 09:09

Gabriele Mariotti