tradle / react-native-udp

node's dgram for react-native
MIT License
339 stars 154 forks source link

Lint error for WIFI_SERVICE memory leak #57

Closed burdiuz closed 6 years ago

burdiuz commented 7 years ago

Hi!

While building application based on RN 48.4 with react-native-udp, I've faced this error

:app:compileReleaseNdk UP-TO-DATE
:app:compileReleaseSources
:app:lintVitalRelease
D:\www\my\ReactNativePlayground\node_modules\react-native-udp\android\src\main\java\com\tradle\react\UdpSockets.java:174:  Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices < Android N. Try changing getReactApplicationContext() to getReactApplicationContext().getApplicationContext()  
[WifiManagerLeak]
WifiManager wifiMgr = (WifiManager) getReactApplicationContext()
                                                        ^

   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(...).

1 errors, 0 warnings
:app:lintVitalRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Lint found fatal errors while assembling a release target.

To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}
...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

As a workaround, solution described above can be used.

mvayngrib commented 7 years ago

@burdiuz context.getApplicationContext().getSystemService(...) sounds like the way to go. Want to send a PR?

mateuszdargacz commented 6 years ago

@mvayngrib is there any update on that?

LuisBL commented 6 years ago

get this Pb too here

mvayngrib commented 6 years ago

@mateuszdargacz @LuisBL fixed in https://github.com/tradle/react-native-udp/commit/c48e42d4497a3275e08776aac197aa978bea84dd, released in 2.3.1