无法导入Android Studio通知频道

时间:2017-07-21 08:12:25

标签: android android-gradle android-notifications

我正在检查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'
}

链接到Google的代码: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'

1 个答案:

答案 0 :(得分:7)

要导入通知渠道,您需要更新 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