react-native-push-notification can not build in an

2020-07-20 04:52发布

问题:

I'll be using react-native-push-notification for notifications in my app but when I use this library it gives me error like this.....

> Task :react-native-push-notification:compileDebugJavaWithJavac FAILED
E:\AndroidNotify\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotificationHelper.java:7: error: cannot find symbol
import android.app.NotificationChannel;
                  ^
  symbol:   class NotificationChannel
  location: package android.app
E:\AndroidNotify\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotificationHelper.java:480: error: cannot find symbol
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
                                                       ^
  symbol:   variable O
  location: class VERSION_CODES
E:\AndroidNotify\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotificationHelper.java:488: error: cannot find symbol
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
                                            ^
  symbol:   variable IMPORTANCE_DEFAULT
  location: class NotificationManager
E:\AndroidNotify\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotificationHelper.java:489: error: cannot find symbol
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
        ^
  symbol:   class NotificationChannel
  location: class RNPushNotificationHelper
E:\AndroidNotify\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotificationHelper.java:489: error: cannot find symbol
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
                                          ^
  symbol:   class NotificationChannel
  location: class RNPushNotificationHelper
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
5 errors

回答1:

Try to upgrade on react-native-push-notification/android/build.gradle this dependencies

  • def DEFAULT_COMPILE_SDK_VERSION = 26
  • def DEFAULT_BUILD_TOOLS_VERSION = "26.1.0"
  • def DEFAULT_TARGET_SDK_VERSION = 23
  • def DEFAULT_SUPPORT_LIB_VERSION = "26.1.0"
  • def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "+"
  • def DEFAULT_FIREBASE_MESSAGING_VERSION = "+"

let me know if that helps you

Error whith RNPushNotifications android



回答2:

I've had this problem also, after fixing the deprecated 'compile' issue in the dependency configurations - module's build.gradle, however, I didn't change the SDK versions there, instead I've added API Level 28 on SDK Platforms in Android Studio and ... voilà.



回答3:

Increase the complieSDK >= 26 (Oreo). Notification channel was introduced in Oreo or SDK 26