11package  com .helloworld ;
22
33import  android .app .Application ;
4- import  android .util .Log ;
5- 
4+ import  android .content .Context ;
65import  com .facebook .react .PackageList ;
7- import  com .facebook .hermes .reactexecutor .HermesExecutorFactory ;
8- import  com .facebook .react .bridge .JavaScriptExecutorFactory ;
96import  com .facebook .react .ReactApplication ;
107import  com .facebook .react .ReactNativeHost ;
118import  com .facebook .react .ReactPackage ;
129import  com .facebook .soloader .SoLoader ;
13- 
10+ import   java . lang . reflect . InvocationTargetException ; 
1411import  java .util .List ;
1512
1613public  class  MainApplication  extends  Application  implements  ReactApplication  {
1714
18-   private  final  ReactNativeHost  mReactNativeHost  = new  ReactNativeHost (this ) {
19-     @ Override 
20-     public  boolean  getUseDeveloperSupport () {
21-       return  BuildConfig .DEBUG ;
22-     }
15+   private  final  ReactNativeHost  mReactNativeHost  =
16+       new  ReactNativeHost (this ) {
17+         @ Override 
18+         public  boolean  getUseDeveloperSupport () {
19+           return  BuildConfig .DEBUG ;
20+         }
2321
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-     }
22+          @ Override 
23+          protected  List <ReactPackage > getPackages () {
24+            @ SuppressWarnings ("UnnecessaryLocalVariable" )
25+            List <ReactPackage > packages  = new  PackageList (this ).getPackages ();
26+            // Packages that cannot be autolinked yet can be added manually here, for example: 
27+            // packages.add(new MyReactNativePackage()); 
28+            return  packages ;
29+          }
3230
33-     @ Override 
34-     protected  String  getJSMainModuleName () {
35-       return  "index" ;
36-     }
37-   };
31+          @ Override 
32+          protected  String  getJSMainModuleName () {
33+            return  "index" ;
34+          }
35+        };
3836
3937  @ Override 
4038  public  ReactNativeHost  getReactNativeHost () {
@@ -45,5 +43,32 @@ public ReactNativeHost getReactNativeHost() {
4543  public  void  onCreate () {
4644    super .onCreate ();
4745    SoLoader .init (this , /* native exopackage */  false );
46+     initializeFlipper (this ); // Remove this line if you don't want Flipper enabled 
47+   }
48+ 
49+   /** 
50+    * Loads Flipper in React Native templates. 
51+    * 
52+    * @param context 
53+    */ 
54+   private  static  void  initializeFlipper (Context  context ) {
55+     if  (BuildConfig .DEBUG ) {
56+       try  {
57+         /* 
58+          We use reflection here to pick up the class that initializes Flipper, 
59+         since Flipper library is not available in release mode 
60+         */ 
61+         Class <?> aClass  = Class .forName ("com.facebook.flipper.ReactNativeFlipper" );
62+         aClass .getMethod ("initializeFlipper" , Context .class ).invoke (null , context );
63+       } catch  (ClassNotFoundException  e ) {
64+         e .printStackTrace ();
65+       } catch  (NoSuchMethodException  e ) {
66+         e .printStackTrace ();
67+       } catch  (IllegalAccessException  e ) {
68+         e .printStackTrace ();
69+       } catch  (InvocationTargetException  e ) {
70+         e .printStackTrace ();
71+       }
72+     }
4873  }
4974}
0 commit comments