android java.lang.NoSuchMethodError:没有静态方法是AtLeastR()Z

bqujaahr  于 2022-12-16  发布在  Android
关注(0)|答案(5)|浏览(214)

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);
6rqinv9w

6rqinv9w1#

我在使用React Native时也遇到了这个问题。我通过在我的app/build.gradle中设置这个来修复它:

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

这是因为Google play-services-base library几天前引入了一个突破性的变化。如果你使用implementation 'com.google.android.gms:play-services-base:+',它将下载最新版本的库,从而将bug引入你的应用。希望这能有所帮助。

igetnqfo

igetnqfo2#

/**
     * 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是一个最终版本,不再需要此方法。它将在支持库的未来版本中删除。
请降级版本

implementation 'com.google.android.gms:play-services-base:17.1.0'
 implementation 'com.google.android.gms:play-services-base:17.0.0' //OR
b1uwtaje

b1uwtaje3#

bug是在com.google.android.gms:play-services-base:17.2.0之前的答案说降级到17.1.0是正确的,但谷歌现在已经修复了这个问题,所以你可以升级到17.2.1,它也工作正常。
这三个是一起更新的,所以如果你正在使用它们,请把它们都提高:

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

来源:https://developers.google.com/android/guides/releases

vltsax25

vltsax254#

我通过在我的app/build.gradle中设置这个来修复它

dependencies {
    // ...
    configurations.all {
        resolutionStrategy.force 'com.google.android.gms:play-services-base:17.1.0'
    }
}
prdp8dxp

prdp8dxp5#

对我来说,在我构建apk之后,@jaymin描述的同样的错误发生了。
我的错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xxx, PID: 11111
    java.lang.NoSuchMethodError: No static method loadImage$default(Landroid/widget/ImageView;Landroid/content/Context;Ljava/lang/String;Landroid/graphics/drawable/Drawable;ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;ZILjava/lang/Object;)V in class Lcom/...; or its super classes (declaration of 'com.xxx.xxx.android.commonui.GlideModuleKt' appears in /data/app/~~NHbxxxx_xxxxw==/com.xxx-kxx-xxxxxxxxxxxxxxxMA==/base.apk!classes8.dex)

(在此之前,该应用程序工作得非常好)。为了修复它,我清除该高速缓存(build,idea,gradle in project and under... user/.gradle),重新安装应用程序和Android Studio -所有这些都是免费的。
最后,我重命名了错误中提到的方法(例如loadImage to loadImageTwo and back to loadImage),并运行了应用程序。应用程序工作正常。我创建了apk,但新名称(loeadImageTwo)仍然很好。之后,我重命名了方法(loadImage),并重复了这些步骤,现在所有工作都很顺利。
我花了一段时间才弄明白,所以如果这也能帮助别人,那将是值得我花时间的。

相关问题