android - 导入 android.app.NotificationChannel 错误
问题描述
尝试编译我的 android React-native 应用程序时出现以下错误。
:react-native-push-notification:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/tmp/workspace/my-develop/my_app/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
/tmp/workspace/my-develop/my_app/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
/tmp/workspace/my-develop/my_app/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
/tmp/workspace/my-develop/my_app/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
/tmp/workspace/my-develop/my_app/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: /tmp/workspace/my-develop/my_app/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/helpers/ApplicationBadgeHelper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
5 errors
:react-native-push-notification:compileReleaseJavaWithJavac FAILED
我读过各种帖子说这个问题可以通过设置来解决compileSdkVersion 26
。但是我已经把这个设置为26
. 我还没有看到任何其他可能导致此问题的建议。
解决方案
安卓/build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
安卓/应用程序/build.gradle:
compileSdkVersion 26
buildToolsVersion "26.0.2"
...
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 22
...
}
在 react-native-push-notification/android/build.gradle 里面
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3' //-----> Changed this from 2.1.3
}
def DEFAULT_COMPILE_SDK_VERSION = 27
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
定义 DEFAULT_TARGET_SDK_VERSION = 26
def DEFAULT_SUPPORT_LIB_VERSION = "26.+"
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "+"
def DEFAULT_FIREBASE_MESSAGING_VERSION = "+"
推荐阅读
- ruby - Ruby:我用 JavaScript 编写的程序在 Ruby 中的工作方式不同
- c# - System.Diagnostics.Process.HasExited 始终返回 true,并且 Process.Exited 事件处理程序始终在进程仍处于打开状态时命中
- android - Android使ViewPager滚动父活动布局
- javascript - javascript条件逻辑运算符
- javascript - 推送到数组时,Typescript undefined 不是对象
- sql - 在 SQL Server 中连接两个无关系的 Count(*) 表
- python - 比较 db 和 csv 文件中字符串的拼写
- firebase - 返回到以前的版本 - Firebase 托管
- javascript - Vue v-bind 条件本地文件
- javascript - 本地存储变量被锁定为 false