javascriptjavareact-nativekotlinreact-native-community-netinfo

Task :react-native-community_netinfo:compileDebugJavaWithJavac FAILED


When i add this library @react-native-community/netinfo i get this error otherwise my app runs fine. it only happens for android it works perfectly on mac for iOS. ive tried cleaning gradle adding ANDROIDHOME to env adding paths for them

Nothing works

"react-native": "0.70.5",
"react-native-actions-sheet": "^0.7.2",
"react-native-chart-kit": "^6.12.0",
"react-native-cli": "^2.0.1",
"@react-native-community/netinfo": "^11.3.2",

Following is the error im getting when i add the netinfo library to the app. when im using ios its working fine the app starts. but when i move to android i get this error when starting the app

See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
153 actionable tasks: 147 executed, 6 up-to-date
Warning: This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.
Note: D:\Projects\ReactNative\Project\node_modules\@react-native-async-storage\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: D:\Projects\ReactNative\Project\node_modules\@react-native-async-storage\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStoragePackage.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
D:\Projects\ReactNative\Project\node_modules\@react-native-community\netinfo\android\src\main\java\com\reactnativecommunity\netinfo\NetInfoUtils.java:45: error: cannot find symbol
                    receiver, filter, exported ? Context.RECEIVER_EXPORTED : Context.RECEIVER_NOT_EXPORTED);
                                                        ^
  symbol:   variable RECEIVER_EXPORTED
  location: class Context
D:\Projects\ReactNative\Project\node_modules\@react-native-community\netinfo\android\src\main\java\com\reactnativecommunity\netinfo\NetInfoUtils.java:45: error: cannot find symbol
                    receiver, filter, exported ? Context.RECEIVER_EXPORTED : Context.RECEIVER_NOT_EXPORTED);
                                                                                    ^
  symbol:   variable RECEIVER_NOT_EXPORTED
  location: class Context
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-community_netinfo:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

My Build Gradle is

buildscript {
    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 21
        compileSdkVersion = 32
        targetSdkVersion = 33
        kotlinVersion = "1.6.10"

        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "24.0.8215888"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath ('com.android.tools.build:gradle:2.3.1')
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:5.0.1")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" // <- add this line
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }
        google()
        maven { url 'https://www.jitpack.io' }
    }
}

My JDK is 17


Solution

  • If anyone has the same issue. i fixed mine by using an older version of netinfo 9.3.10 worked for me