gpt4 book ai didi

java - react-native-notifications 在 iOS 上工作,在 Android 上失败

转载 作者:行者123 更新时间:2023-12-03 11:17:43 26 4
gpt4 key购买 nike

我已经安装了 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.java getPackages()方法,它说这个包已经与这个错误相关联:(下图)
    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
    }
    }

    enter image description here

    enter image description here

    我真的很想使用这个包,因为它在 iOS 上运行得非常好。有什么帮助,谢谢!

    更新:
    解决方法是 react-native-push-notification依赖。但是,如果 react-native-notifications包已安装。我不确定它是否值得报告错误,或者是否有通过我的 WebStorm CLI 或类似的东西启用 Java 权限的修复程序。

    最佳答案

    遇到了同样的错误,幸运的是我能够通过在平台检查中封装 IOS 部分来修复它,例如:

    if(Platform.OS === 'ios'){
    PushNotificationIOS.removeAllDeliveredNotifications();
    }

    关于java - react-native-notifications 在 iOS 上工作,在 Android 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61979573/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com