diff --git a/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.java b/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.java index 8ed784fe5af7c4..3cd44b6d022aae 100644 --- a/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.java +++ b/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.java @@ -25,6 +25,11 @@ import com.facebook.react.modules.network.NetworkingModule; import okhttp3.OkHttpClient; +/** + * Class responsible of loading Flipper inside your React Native application. + * This is the debug flavor of it. Here you can add your own plugins and customize + * the Flipper setup. + */ public class ReactNativeFlipper { public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { if (FlipperUtils.shouldEnableFlipper(context)) { diff --git a/template/android/app/src/main/java/com/helloworld/MainApplication.java b/template/android/app/src/main/java/com/helloworld/MainApplication.java index eedd192958b993..637e984cd36e35 100644 --- a/template/android/app/src/main/java/com/helloworld/MainApplication.java +++ b/template/android/app/src/main/java/com/helloworld/MainApplication.java @@ -10,7 +10,6 @@ import com.facebook.react.config.ReactFeatureFlags; import com.facebook.soloader.SoLoader; import com.helloworld.newarchitecture.MainApplicationReactNativeHost; -import java.lang.reflect.InvocationTargetException; import java.util.List; public class MainApplication extends Application implements ReactApplication { @@ -55,37 +54,7 @@ public void onCreate() { // If you opted-in for the New Architecture, we enable the TurboModule system ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; SoLoader.init(this, /* native exopackage */ false); - initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); + ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); } - /** - * Loads Flipper in React Native templates. Call this in the onCreate method with something like - * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); - * - * @param context - * @param reactInstanceManager - */ - private static void initializeFlipper( - Context context, ReactInstanceManager reactInstanceManager) { - if (BuildConfig.DEBUG) { - try { - /* - We use reflection here to pick up the class that initializes Flipper, - since Flipper library is not available in release mode - */ - Class aClass = Class.forName("com.helloworld.ReactNativeFlipper"); - aClass - .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) - .invoke(null, context, reactInstanceManager); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - } - } } diff --git a/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.java b/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.java new file mode 100644 index 00000000000000..557146643df0fe --- /dev/null +++ b/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + *

This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + */ +package com.helloworld; + +import android.content.Context; +import com.facebook.react.ReactInstanceManager; + +/** + * Class responsible of loading Flipper inside your React Native application. + * This is the release flavor of it so it's empty as we don't want to load Flipper. + */ +public class ReactNativeFlipper { + public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { + // Do nothing as we don't want to initialize Flipper on Release. + } +}