java.lang.NoSuchMethodError: No static method isAt

2020-07-06 08:39发布

My app was running fine but suddenly I started getting this error

java.lang.NoSuchMethodError: No static method isAtLeastR()Z in class Landroidx/core/os/BuildCompat; or its super classes (declaration of 'androidx.core.os.BuildCompat' appears in /data/app/com.app.goflatmates-RZKwS2h6hav==/base.apk) at com.google.android.gms.common.util.PlatformVersion.isAtLeastR(com.google.android.gms:play-services-basement@@17.2.0:21) at com.google.android.gms.common.api.GoogleApi.zaa(com.google.android.gms:play-services-base@@17.2.0:128) at com.google.android.gms.common.api.GoogleApi.(com.google.android.gms:play-services-base@@17.2.0:23) at com.google.android.gms.common.api.GoogleApi.(com.google.android.gms:play-services-base@@17.2.0:54) at com.google.android.gms.auth.api.signin.GoogleSignInClient.(Unknown Source:3) at com.google.android.gms.auth.api.signin.GoogleSignIn.getClient(Unknown Source:3

The problem is coming in this line

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build(); 

mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

4条回答
神经病院院长
2楼-- · 2020-07-06 09:25

The bug was in com.google.android.gms:play-services-base:17.2.0 The previous answers saying to downgrade to 17.1.0 were correct, but Google has fixed the issue now, so you can upgrade to 17.2.1 and it also works fine.

These three were updated together, so bump them all up if you're using them:

com.google.android.gms:play-services-base:17.2.1
com.google.android.gms:play-services-basement:17.2.1
com.google.android.gms:play-services-tasks:17.0.2

Source: https://developers.google.com/android/guides/releases

查看更多
beautiful°
3楼-- · 2020-07-06 09:34

I fixed it by setting this in my app/build.gradle

dependencies {
    // ...
    configurations.all {
        resolutionStrategy.force 'com.google.android.gms:play-services-base:17.1.0'
    }
}
查看更多
乱世女痞
4楼-- · 2020-07-06 09:37
/**
     * Checks if the device is running on a pre-release version of Android R or newer.
     * <p>
     * <strong>Note:</strong> This method will return {@code false} on devices running release
     * versions of Android. When Android R is finalized for release, this method will be deprecated
     * and all calls should be replaced with {@code Build.VERSION.SDK_INT >= Build.VERSION_CODES.R}.
     *
     * @return {@code true} if R APIs are available for use, {@code false} otherwise
     */
    public static boolean isAtLeastR() {
        return VERSION.CODENAME.length() == 1 && VERSION.CODENAME.charAt(0) >= 'R'
                && VERSION.CODENAME.charAt(0) <= 'Z';
    }

Android Q is a finalised release and this method is no longer necessary. It will be removed in a future release of the Support Library.

Kindly downgrade version

 implementation 'com.google.android.gms:play-services-base:17.1.0'
 implementation 'com.google.android.gms:play-services-base:17.0.0' //OR
查看更多
beautiful°
5楼-- · 2020-07-06 09:41

I had this issue with React Native as well. I fixed it by setting this in my app/build.gradle:

dependencies {
    // ...
    implementation 'com.google.android.gms:play-services-base:17.1.0'
    // ...
}

It's because of a breaking change introduced by Google play-services-base library a couple days ago. If you use implementation 'com.google.android.gms:play-services-base:+' it will download the latest version of the library, introducing that bug into your app. Hope that helps.

查看更多
登录 后发表回答