我已经安装了 react-native-notifications 并且在 iOS 上一切正常,但它在 Android 上总是给我错误。我已按照此处的确切 Android 安装说明进行操作:https ://wix.github.io/react-native-notifications/docs/installation-android
我的开发流程:
- 进行修改。
npx react-native clean-project-auto; npx react-native-clean-project
rm -rf android/app/build; anroid/gradlew clean; android/gradlew build --refresh-dependencies
npx react-native start --reset-cache
- Android Studio 使缓存无效/重新启动。
- Android Studio 干净构建。
- Android Studio 同步 Gradle 文件并运行应用程序。
npx react-native run-android --deviceId emulator-5554
步骤 7. 结果Invariant Violation: PushNotificationManager is not available.
(下图)
步骤 8. 产生以下日志:
...
> Task :react-native-notifications:testReactNative60DebugUnitTest
...
com.wix.reactnativenotifications.core.InitialNotificationHolderTest > replacesInitialNotification PASSED
com.wix.reactnativenotifications.core.InitialNotificationHolderTest > isALazySingleton PASSED
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.robolectric.util.ReflectionHelpers$6 (file:/[path]/.gradle/caches/transforms-2/files-2.1/4e5696f3256b4082eea0964d812439f4/jetified-shadowapi-4.3.jar) to method java.lang.ClassLoader.getPackage(java.lang.String)
WARNING: Please consider reporting this to the maintainers of org.robolectric.util.ReflectionHelpers$6
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
com.wix.reactnativenotifications.core.notification.PushNotificationTest > onPostRequest_emptyData_postNotification FAILED
java.lang.RuntimeException
Caused by: java.lang.RuntimeException
Caused by: java.lang.IllegalAccessException
...
当我将包添加packages.add(new RNNotificationsPackage(MainApplication.this))
到 MainApplication.javagetPackages()
方法时,它说这个包已经与此错误相关联:(下图)
E/unknown:ReactNative: Exception in native call
java.lang.IllegalStateException: Native module RNBridgeModule tried to override RNNotificationsModule. Check the getPackages() method in MainApplication.java, it might be that module is being created twice. If this was your intention, set canOverrideExistingModule=true. This error may also be present if the package is present only once in getPackages() but is also automatically added later during build time by autolinking. Try removing the existing entry and rebuild.
at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:55)
at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1298)
at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1269)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1194)
at com.facebook.react.ReactInstanceManager.access$1000(ReactInstanceManager.java:132)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:996)
at java.lang.Thread.run(Thread.java:919)
依赖项:
"@react-native-community/push-notification-ios": "^1.2.0"
"react-native-notifications": "^3.2.1",
应用程序/build.gradle
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation project(':react-native-notifications')
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.google.firebase:firebase-analytics:17.3.0'
addUnimodulesDependencies()
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
安卓/build.gradle
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 21
compileSdkVersion = 28
targetSdkVersion = 29
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.google.gms:google-services:4.3.3' // Google Services plugin
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
我真的很想使用这个包,因为它在 iOS 上运行得非常好。有什么帮助,谢谢!
更新:
解决方法是react-native-push-notification
依赖项。react-native-notifications
但是,如果安装了软件包,上面的第 8 步仍然会导致错误。我不确定它是否值得报告错误,或者是否有通过我的 WebStorm CLI 或类似的东西启用 Java 权限的修复程序。