Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...