Include Stetho only in the debug build variant

后端 未结 4 2157
醉话见心
醉话见心 2020-11-29 02:10

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

4条回答
  •  旧时难觅i
    2020-11-29 02:46

    Using java reflection may be a perferct idea:

    private void initStetho() {
                if (BuildConfig.DEBUG) {
                    try {
                       Class stethoClazz = Class.forName("com.facebook.stetho.Stetho");
                        Method method = stethoClazz.getMethod("initializeWithDefaults",Context.class);
                        method.invoke(null, this);
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
            }
    

    then we can debug compile stetho:

    debugCompile 'com.facebook.stetho:stetho:1.5.0'
    

提交回复
热议问题