react-native-push-notification无法在android中构建

时间:2018-08-04 04:33:40

标签: react-native

我将在我的应用程序中使用react-native-push-notification进行通知,但是当我使用此库时,它给我这样的错误.....

> 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

3 个答案:

答案 0 :(得分:3)

尝试在react-native-push-notification / android / build.gradle上升级此依赖项

  • 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 =“ +”

让我知道这是否对您有帮助

Error whith RNPushNotifications android

答案 1 :(得分:0)

在将deprecated 'compile' issue固定为dependency configurations - module's build.gradle之后,我也遇到了这个问题,但是我没有在那里更改SDK versions,而是添加了{{1 }}在API Level 28中的SDK Platforms上,并且...voilà。

答案 2 :(得分:0)

增加complieSDK> = 26(奥利奥)。 通知频道是在Oreo或SDK 26中引入的