任务:react-native-community_netinfo:compileDebugJavaWithJavac失败

问题描述 投票:0回答:1

当我添加此库 @react-native-community/netinfo 时,我会收到此错误,否则我的应用程序运行正常。它只发生在 Android 上,它在 iOS 的 Mac 上完美运行。我尝试过清洁等级 将 ANDROIDHOME 添加到环境中 为它们添加路径

没有任何效果

"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",

以下是将 netinfo 库添加到应用程序时出现的错误。当我使用 ios 时,它工作正常,应用程序启动。但是当我转向 Android 时,启动应用程序时出现此错误

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.

我的构建 Gradle 是

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' }
    }
}

我的JDK是17

javascript java react-native kotlin react-native-community-netinfo
1个回答
0
投票

如果有人有同样的问题。我使用旧版本的 netinfo 修复了我的问题 9.3.10 为我工作

© www.soinside.com 2019 - 2024. All rights reserved.