我迁移到较新的 React Native 并将一些库更新到最新版本。我的一块project.json
:
"@react-native-community/async-storage": "^1.4.1",
"@react-native-community/netinfo": "^3.1.1",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-react-native": "^4.0.0",
"react": "16.8.6",
"react-native": "^0.59.8"
我在这里遇到了这个问题:
D:\myapp\node_modules@react-native-community\netinfo\android\src\main\java\com\reactnativecommunity\netinfo\ConnectivityReceiver.java:12:错误:包android.support.v4.net不存在导入android .support.v4.net.ConnectivityManagerCompat;^ D:\myapp\node_modules@react-native-community\netinfo\android\src\main\java\com\reactnativecommunity\netinfo\ConnectivityReceiver.java:154:错误:找不到符号 ConnectivityManagerCompat.isActiveNetworkMetered(getConnectivityManager()); ^ 符号:变量 ConnectivityManagerCompat 位置:类 ConnectivityReceiver 2 错误
gradle.properties
android.enableJetifier = true
android.useAndroidX=true
根梯度
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 21
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion="28.0.0"
}
梯度依赖
dependencies {
implementation project(':react-native-code-push')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-webview')
implementation project(':react-native-push-notification')
implementation project(':@react-native-community_netinfo')
implementation project(':@react-native-community_async-storage')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation 'com.google.firebase:firebase-messaging:+'
implementation 'com.facebook.react:react-native:+'
}