I was examining the firebase messaging features for android and checked a sample project about it. When I wrote the code my app can import Notification Manager but it cannot import Notification Channel. My gradle file can be found below.
import android.app.NotificationChannel;
import android.app.NotificationManager;
My gradle dependencies
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 of google's project.
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'
}
Link to google's code : https://github.com/firebase/quickstart-android/blob/master/messaging/app/build.gradle '
Edit: All of gradle file.
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'
To import notification channel you need to update your 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
}
Note: It will crash on this line while running on API version < 26, so you have to handle that.
final NotificationChannel notificationChannel = new
NotificationChannel(channelId, channelName, importance);
with following exception
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/app/NotificationChannel;
...
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.app.NotificationChannel" on path: DexPathList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With