无法在 android studio 3.4.1 中解析符号 'NotificationCompat '
Cannot resolve symbol 'NotificationCompat ' in android studio 3.4.1
我是 Android 的新手,收到错误消息:"NotificationCompat cannot be resolved to a type"
MinSDK=18, TargetSDK=28, Android Gradle 插件版本=3.4.1, gradle 版本=5.1.1 如何解决这个错误帮助我
我的 gradle 文件如下
dependencies {
implementation "com.android.support:support-core-utils:28.0.0"
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha5'
testImplementation 'junit:junit:4.13-beta-2'
'com.android.support.test:runner:1.0.2'
implementation "com.android.support:support-core-utils:28.0.0"
implementation 'com.google.code.gson:gson:2.8.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-compat:28.0.0'
}
有notificationCompat错误的代码
protected android.support.v7.app.NotificationCompat.Action getStopAction() {
Intent intent = new Intent(WIFI_AP_ACTION_STOP);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return new android.support.v7.app.NotificationCompat.Action.Builder(android.R.drawable.ic_menu_close_clear_cancel, "Stop", pendingIntent).build();
尽管您的构建 gradle 中有 implementation 'com.android.support:appcompat-v7:28.0.0'
,但 class 路径是 android.support.v4.app.NotificationCompat.Action
(不是 v7.app...
)
你也可以确认HERE(注意包路径上的V4)
所以,只需将您的方法更新为:
protected android.support.v4.app.NotificationCompat.Action getStopAction() { ... }
对于 sdk 28,您需要使用:
java.lang.Object
↳ androidx.core.app.NotificationCompat
我是 Android 的新手,收到错误消息:"NotificationCompat cannot be resolved to a type"
MinSDK=18, TargetSDK=28, Android Gradle 插件版本=3.4.1, gradle 版本=5.1.1 如何解决这个错误帮助我
我的 gradle 文件如下
dependencies {
implementation "com.android.support:support-core-utils:28.0.0"
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha5'
testImplementation 'junit:junit:4.13-beta-2'
'com.android.support.test:runner:1.0.2'
implementation "com.android.support:support-core-utils:28.0.0"
implementation 'com.google.code.gson:gson:2.8.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-compat:28.0.0'
}
有notificationCompat错误的代码
protected android.support.v7.app.NotificationCompat.Action getStopAction() {
Intent intent = new Intent(WIFI_AP_ACTION_STOP);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return new android.support.v7.app.NotificationCompat.Action.Builder(android.R.drawable.ic_menu_close_clear_cancel, "Stop", pendingIntent).build();
尽管您的构建 gradle 中有 implementation 'com.android.support:appcompat-v7:28.0.0'
,但 class 路径是 android.support.v4.app.NotificationCompat.Action
(不是 v7.app...
)
你也可以确认HERE(注意包路径上的V4)
所以,只需将您的方法更新为:
protected android.support.v4.app.NotificationCompat.Action getStopAction() { ... }
对于 sdk 28,您需要使用: java.lang.Object ↳ androidx.core.app.NotificationCompat