Chr*_*ant 7 java android react-native react-native-notifications
我已经安装了 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-projectrm -rf android/app/build; anroid/gradlew clean; android/gradlew build --refresh-dependenciesnpx react-native start --reset-cachenpx 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
...
Run Code Online (Sandbox Code Playgroud)
当我将包添加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)
Run Code Online (Sandbox Code Playgroud)
依赖项:
"@react-native-community/push-notification-ios": "^1.2.0"
"react-native-notifications": "^3.2.1",
Run Code Online (Sandbox Code Playgroud)
应用程序/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
}
}
Run Code Online (Sandbox Code Playgroud)
android/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
}
}
Run Code Online (Sandbox Code Playgroud)
我真的很想使用这个包,因为它在 iOS 上运行得非常好。有什么帮助,谢谢!
更新:
解决这个问题的方法是react-native-push-notification依赖。但是,如果react-native-notifications安装了软件包,上面的步骤 8 仍然会导致错误。我不确定它是否值得报告错误,或者是否有修复程序可以通过我的 WebStorm CLI 或类似的东西启用 Java 权限。
小智 0
遇到了同样的错误,幸运的是我能够通过将 IOS 部分封装在平台检查中来修复它,例如:
if(Platform.OS === 'ios'){
PushNotificationIOS.removeAllDeliveredNotifications();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1380 次 |
| 最近记录: |