devstepbcn / react-native-android-wifi

A react-native module for viewing and connecting to Wifi networks on Android devices.
ISC License
212 stars 121 forks source link

Error: The WIFI_SERVICE must be looked up on the Application context #80

Open katjajohanna opened 5 years ago

katjajohanna commented 5 years ago

When I'm building a release of my application, I get this error:

react-native-android-wifi/android/src/main/java/com/devstepbcn/wifi/AndroidWifiModule.java:49: Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices < Android N. Try changing reactContext to reactContext.getApplicationContext()  [WifiManagerLeak]
  wifi = (WifiManager)reactContext.getSystemService(Context.WIFI_SERVICE);
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   Explanation for issues of type "WifiManagerLeak":
   On versions prior to Android N (24), initializing the WifiManager via
   Context#getSystemService can cause a memory leak if the context is not the
   application context. Change context.getSystemService(...) to
   context.getApplicationContext().getSystemService(...).

Is it possible to update the package?

Versions I'm using:

react-native: 0.56.1
react-native-android-wifi: 0.0.40
katjajohanna commented 5 years ago

Here's a pull request to fix this: https://github.com/devstepbcn/react-native-android-wifi/pull/81