我在不同的android库中看到了很多有关检测设备是否支持LOLLIPOP的示例。但是,当我在应用程序中使用它时,它会引发以下错误:


  错误:(20,60)错误:找不到符号变量LOLLIPOP


例如,我的源代码是:

static boolean isLollipop() {
    return Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1;
}


我正在使用最新版本的Android Studio,并已更新和安装了所有软件包。

此语句有错误:

Build.VERSION_CODES.LOLLIPOP


另外,当我检查VERSION_CODES的选项时,该列表中不存在LOLLIPOP

最佳答案

似乎您正在使用旧的构建工具,或者您缺少一些库。

我将您的代码粘贴到了Android Studio中,并且可以正常工作。

请将此build.gradle与以下内容进行比较:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23           //THIS GUY
    buildToolsVersion "23.0.2"    //THIS GUY

    defaultConfig {
        applicationId "com.example.piotr.myapplication"
        minSdkVersion 15
        targetSdkVersion 23     //THIS GUY
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1' //THIS GUY
    compile 'com.android.support:design:23.1.1'
}


我已经匹配了可能对您的代码很重要的部分。

希望对你有帮助

关于android - 错误:找不到符号变量LOLLIPOP,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34623729/

10-11 22:51
查看更多