简体   繁体   中英

java.lang.NoSuchMethodError: No static method isDeviceProtectedStorage

I am trying to implement firebase into my project. But when the program run for the first time it shows this error :

 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)

and below is my gradle :

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'

I've read somewhere else it may be due to lower version of v4 support library. so I had it changed to higher api level, but the problem still persist. Any solution to solve this problem??

Reason of this exception is AppCompatActivity derived from the v7 library. so we should provide proper library based on your gradle and SDK.

You should update the dependency Libraries also.

Right click on the project in the project structure -> select Open module settings and select dependencies tab -> Library module-> then type which library you want add to the project. It shows the latest libraries based on your gradle updated version, then select latest one and remove the existing one. For example In my project "appcompat-v7" version was 23.4.0 then I was changed to 27.0.2 which is latest one

Or try to use

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM