无法导入 Android Studio 通知频道



我正在检查适用于Android的Firebase消息传递功能,并检查了一个有关它的示例项目。当我编写代码时,我的应用程序可以导入通知管理器,但无法导入通知通道。我的 gradle 文件可以在下面找到。

import android.app.NotificationChannel;
import android.app.NotificationManager;

我的 gradle 依赖项

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-compat:25.0.0-beta2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.google.android.gms:play-services:11.0.2'
compile 'com.google.firebase:firebase-messaging:11.0.2'
compile 'com.google.firebase:firebase-core:11.0.2

谷歌项目的依赖关系。

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.0.0-beta2'
compile 'com.android.support:animated-vector-drawable:26.0.0-beta2'
compile 'com.android.support:support-compat:26.0.0-beta2'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'com.firebase:firebase-jobdispatcher:0.6.0'
// Testing dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:25.3.1'
}

链接到谷歌的代码:https://github.com/firebase/quickstart-android/blob/master/messaging/app/build.gradle '

编辑:所有 gradle 文件。

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
applicationId 'com.myapp.extranet'
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}

}


dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.iarcuschin:simpleratingbar:0.1.5'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-compat:25.0.0-beta2'
compile 'com.android.support:design:25.3.1'
compile 'com.intuit.sdp:sdp-android:1.0.3'
compile 'com.google.code.gson:gson:2.7'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
compile 'com.miguelcatalan:materialsearchview:1.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
compile 'com.github.clans:fab:1.6.4'
compile 'com.joooonho:selectableroundedimageview:1.0.1'
compile 'com.github.baoyachi:StepView:1.9'
compile 'com.google.android.gms:play-services:11.0.2'
compile 'com.google.firebase:firebase-messaging:11.0.2'
compile 'com.google.firebase:firebase-core:11.0.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

要导入通知通道,您需要更新compileSdkVersion

compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.notificationcomponent"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}

注意:在 API 版本 <26 上运行时,它会在此行上崩溃,因此您必须处理它。

final NotificationChannel notificationChannel = new
NotificationChannel(channelId, channelName, importance);

但以下情况除外

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/app/NotificationChannel;
...
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.app.NotificationChannel" on path: DexPathList

最新更新