11package com .example ;
22
33import android .app .Application ;
4- import android .util . Log ;
4+ import android .content . Context ;
55
66import com .facebook .react .PackageList ;
7- import com .facebook .hermes .reactexecutor .HermesExecutorFactory ;
8- import com .facebook .react .bridge .JavaScriptExecutorFactory ;
97import com .facebook .react .ReactApplication ;
108import com .facebook .react .ReactNativeHost ;
119import com .facebook .react .ReactPackage ;
1210import com .facebook .soloader .SoLoader ;
1311
12+ import java .lang .reflect .InvocationTargetException ;
1413import java .util .List ;
1514
1615public class MainApplication extends Application implements ReactApplication {
17- private final ReactNativeHost mReactNativeHost = new ReactNativeHost (this ) {
18- @ Override
19- public boolean getUseDeveloperSupport () {
20- return BuildConfig .DEBUG ;
21- }
2216
23- @ Override
24- protected List <ReactPackage > getPackages () {
25- @ SuppressWarnings ("UnnecessaryLocalVariable" )
26- List <ReactPackage > packages = new PackageList (this ).getPackages ();
27- // Packages that cannot be autolinked yet can be added manually here, for example:
28- // packages.add(new MyReactNativePackage());
29- return packages ;
30- }
17+ private final ReactNativeHost mReactNativeHost =
18+ new ReactNativeHost (this ) {
19+ @ Override
20+ public boolean getUseDeveloperSupport () {
21+ return BuildConfig .DEBUG ;
22+ }
3123
32- @ Override
33- protected String getJSMainModuleName () {
34- return "index" ;
35- }
36- };
24+ @ Override
25+ protected List <ReactPackage > getPackages () {
26+ @ SuppressWarnings ("UnnecessaryLocalVariable" )
27+ List <ReactPackage > packages = new PackageList (this ).getPackages ();
28+ // Packages that cannot be autolinked yet can be added manually here, for example:
29+ // packages.add(new MyReactNativePackage());
30+ return packages ;
31+ }
32+
33+ @ Override
34+ protected String getJSMainModuleName () {
35+ return "index" ;
36+ }
37+ };
3738
3839 @ Override
3940 public ReactNativeHost getReactNativeHost () {
@@ -44,5 +45,32 @@ public ReactNativeHost getReactNativeHost() {
4445 public void onCreate () {
4546 super .onCreate ();
4647 SoLoader .init (this , /* native exopackage */ false );
48+ initializeFlipper (this ); // Remove this line if you don't want Flipper enabled
49+ }
50+
51+ /**
52+ * Loads Flipper in React Native templates.
53+ *
54+ * @param context
55+ */
56+ private static void initializeFlipper (Context context ) {
57+ if (BuildConfig .DEBUG ) {
58+ try {
59+ /*
60+ We use reflection here to pick up the class that initializes Flipper,
61+ since Flipper library is not available in release mode
62+ */
63+ Class <?> aClass = Class .forName ("com.facebook.flipper.ReactNativeFlipper" );
64+ aClass .getMethod ("initializeFlipper" , Context .class ).invoke (null , context );
65+ } catch (ClassNotFoundException e ) {
66+ e .printStackTrace ();
67+ } catch (NoSuchMethodException e ) {
68+ e .printStackTrace ();
69+ } catch (IllegalAccessException e ) {
70+ e .printStackTrace ();
71+ } catch (InvocationTargetException e ) {
72+ e .printStackTrace ();
73+ }
74+ }
4775 }
4876}
0 commit comments