java.lang.NoSuchMethodError:没有静态方法isDeviceProtectedStorage

时间:2018-02-21 04:11:22

标签: android firebase

我正在尝试将firebase实现到我的项目中。但是当程序第一次运行时会显示此错误:

 java.lang.NoSuchMethodError: No static method isDeviceProtectedStorage(Landroid/content/Context;)Z in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/com.example.project-1/base.apk)

以下是我的傻瓜:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.project"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        multiDexEnabled true
    }
    buildToolsVersion "25.0.1"

    sourceSets {
        main {
            aidl.srcDirs = ['src/aidl']
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile fileTree(dir: 'src/main/jnilibs', include: ['.jar','.so'])
    compile files('libs/gcm.jar')
    compile files('libs/android-support-v7-recyclerview.jar')
    compile files('libs/gson-2.7.jar')
    compile files('libs/httpclientandroidlib-1.2.0.jar')
    compile files('libs/logging-interceptor-3.0.1.jar')
    compile files('libs/okhttp-3.0.1.jar')
    compile files('libs/okhttp-urlconnection-3.0.1.jar')
    compile files('libs/okio-1.10.0.jar')
    compile files('libs/rollbar-android-0.1.3.jar')
    compile files('libs/sherlocknavigationdrawer-1.0.jar')
    compile files('libs/v7compat.jar')
    compile files('libs/mpChart.jar')
    compile files('libs/picasso-2.5.2.jar')
    compile project(':actionbarsherlock')
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'de.hdodenhof:circleimageview:2.2.0'
    compile 'com.google.firebase:firebase-core:11.6.0'
    compile 'com.google.firebase:firebase-messaging:11.6.0'
}

apply plugin: 'com.google.gms.google-services'

我在其他地方读过这可能是由于较低版本的v4支持库造成的。所以我把它改成了更高的api级别,但问题仍然存在。解决这个问题的任何解决方案??

1 个答案:

答案 0 :(得分:0)

  

此异常的原因是从v7库派生的AppCompatActivity。所以我们应该根据你的gradle和SDK提供合适的库。

您还应该更新依赖库。

右键单击项目结构中的项目 - >选择打开模块设置并选择依赖项选项卡 - >库模块 - >然后键入要添加到项目的库。它会根据您的gradle更新版本显示最新的库,然后选择最新的库并删除现有的库。 例如,在我的项目“appcompat-v7”版本 23.4.0 ,然后我被更改为 27.0.2 ,这是最新版本

或尝试使用

compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.android.support:support-v4:27.0.2'
compile 'com.android.support:appcompat-v7:27.0.2'
相关问题